Serialization depth limit 7 exceeded during serialization

Hello,

I’m trying to create a combo system for my game, where each combo would be an array, with different characteristics for each attack in it. To create such combo system, I made the following class:

[System.Serializable]
public class AttackCharacteristics : IAttacks
{
  //diffrerent values for each attack here

    public AttackCharacteristics[] attacks;

    public AttackCharacteristics(int _amount)
    {
        attacks = new AttackCharacteristics[_amount];
    }

    AttackCharacteristics[] IAttacks.attacks()
    {
        return attacks;
    }
}

The problem is that, because I have

public AttackCharacteristics[] attacks;

it buids an infinite structure and I get an error “Serialization depth limit 7 exceeded…”. I can’t use [System.NonSerialized], because I want to manualy enter values for each attack in the inspector, and I can’t find any other workaround to solve this error.

Thanks in advance for your answer.

As a workaround, you can always use index instead of reference. So you have one big array for all AttackCharacteristics and in each AttackCharacteristic you have list of indexes that point to right AttackCharacteristic.

you could user newtonsoftjson instead get the dll and put it into your plugins folder in unity and set ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

and use this instead of [System.Serializable]