Serialization Depth Limit 10 exceeded at UnityEvents?

I’ve hit a wall in trying to solve this myself.

I’ve had this happen before with one of my own custom classes, and I just had to SerializeReference the field and it stopped, I thought this would be the same but I can’t access this script.

I’ve searched through my entire project and found every use of a UnityEvent, I’ve gone through each one and commented them out, the error persists the entire time.

I’ve gone into new scenes, I’ve gone through every prefab and game object in the scene, no events are using missing mono’s. I’ve brought the hiearchy down to just my game instance and it’s still happening, none of the scripts active in the game instance are using UnityEvents.

The only thing I can think of is something to do with this script’s constructors.

 //This is used for NPCs to have a current interaction.
public Interaction(string context, InteractionType type, Interactor actor, Transform interactableObj, UnityEvent<Interaction> uEvent)
{
    _context = context;
    _type = type;
    _actor = actor;
    _object = interactableObj;
    if(interactableObj != null ) 
        _interactable = _object.GetComponent<IInteractable>();

    _event = uEvent;
}

//This is used to clone an Interaction to differentiate event calls, specifically the Withdraw interaction in storage containers
public Interaction(Interaction action)
{
    _context = action._context;
    _type = action._type;
    _actor = action.actor;
    _object = action.Object;
    if (action.Interactable != null)
        _interactable = _object.GetComponent<IInteractable>();

    _event = new UnityEvent<Interaction>();
}

or maybe using a UnityEvent that carries the Interaction class as a type, the interaction in turn serializes a UnityEvent as a variable as well.
[SerializeField] public UnityEvent<Interaction> _event;

That would cause it yes. If your Interaction class serializes a UnityEvent<Interaction>, which in turn serializes another UnityEvent<Interaction>, then that is recursive serialisation.

This might also involve using [SerializeReference] to keep the field null when there is no connection to another interaction, and instantiating a instance when needed.

I made a struct with the information needed, it’s not serializeable, and I’ve changed the UnityEvent to now use the new struct and I’m still getting the error.
image

I finally fixed this,

The issue with my initial solve was my Interactor class had a reference to an Interaction class as _currentInteraction which started the whole cycle again even in it’s own struct.

Basically the fix was to just completely map out all the methods and what was calling what.
The fix is to not reference classes higher on the chain of calls, try and make all your methods trickle down classes and not need to jump back up to one specific component.

Seems really obvious now that it’s all said and done. Also, just object reference works.