Serializable Interface
A wrapper that allows serialization of interfaces that supports both UnityEngine.Object and regular object types
net.tnrd.serializableinterface Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/serializableinterface.git 
README Markdown
Copy this to your project's README.md
## Installation
Add **Serializable Interface** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/serializableinterface.git
```
[](https://www.pkglnk.dev/pkg/serializableinterface)README
Serializable Interface
A wrapper that allows you to serialize interfaces. Both UnityEngine.Object and regular object implementers work!
Installation
- The package is available on the openupm registry. You can install it via openupm-cli.
openupm add net.tnrd.serializableinterface
- Installing through a Unity Package created by the Package Installer Creator from Needle
Usage
Usage is pretty easy and straightforward. Assuming you have the following interface
public interface IMyInterface
{
void Greet();
}
You can add it to a behaviour like so
using TNRD;
using UnityEngine;
public class MyBehaviour : MonoBehaviour
{
[SerializeField] private SerializableInterface<IMyInterface> mySerializableInterface;
private void Awake()
{
mySerializableInterface.Value.Greet();
}
}
Back in the Unity inspector it will look like this

And when you click on the object selector button you will be shown a dropdown window with all possible options like this

As you can see you can select items from multiple locations:
- Assets (Scriptable Objects and Prefabs that implement said interface)
- Classes (custom classes that implement said interface)
- Scene (objects in the scene that implement said interface)
For the sake of example for the image above I have created some simple implementations
using UnityEngine;
public class MyComponent : MonoBehaviour, IMyInterface
{
/// <inheritdoc />
public void Greet()
{
Debug.Log("Hello, World! I'm MyComponent");
}
}
using UnityEngine;
public class MyPoco : IMyInterface
{
/// <inheritdoc />
public void Greet()
{
Debug.Log("Hello, World! I'm MyPoco");
}
}
using UnityEngine;
[CreateAssetMenu(menuName = "MyScriptable")]
public class MyScriptable : ScriptableObject, IMyInterface
{
/// <inheritdoc />
public void Greet()
{
Debug.Log("Hello, World! I'm MyScriptable");
}
}
Support
Serializable Interface is a small and open-source utility that I hope helps other people. It is by no means necessary but if you feel generous you can support me by donating.
Contributions
Pull requests are welcomed. Please feel free to fix any issues you find, or add new features.
Comments
No comments yet. Be the first!
Sign in to join the conversation
Sign In