Skip to content

Interface Serialization

Ilia Petrov-Komotskii edited this page Sep 24, 2026 · 4 revisions

Interface Serialization

Two different jobs:

Attribute Field What you get
[SerializeInterface] [SerializeReference] interface or base class Type picker, then nested instance fields
[InterfaceOnly(typeof(IFoo))] [SerializeField] UnityEngine.Object (usually MonoBehaviour) Object field that must implement the interface
using Mane.Unity;
using UnityEngine;

public interface IWeapon
{
    void Fire();
}

public class Loadout : MonoBehaviour
{
    [SerializeReference, SerializeInterface]
    private IWeapon _equipped;

    [SerializeField, InterfaceOnly(typeof(IDamageable))]
    private MonoBehaviour _target;
}

SerializeInterface is for data (plain C# types on SerializeReference). InterfaceOnly is for scene/prefab references.

Both are Property Drawers. Only one drawer can own a field; Decorators can still wrap it.

Wrong field type (for example InterfaceOnly on an int) draws a warning instead of a broken control.

Screenshot: serialize-interface.png — SerializeReference field with the type dropdown open. Host at https://raw.githubusercontent.com/wiki/ManeFunction/ManeTools-Unity/serialize-interface.png.

Screenshot: interface-only.png — Object field plus the “must implement interface” warning. Host at https://raw.githubusercontent.com/wiki/ManeFunction/ManeTools-Unity/interface-only.png.

Clone this wiki locally