how i can make a loop class display on inspector without using [system.serializable] because happen this error:
Serialization depth limit exceeded at ‘PlayerTalkLine’. There may be an object composition cycle in one or more of your serialized classes.
script
[System.Serializable]
public class TalkLine{
public string DiagLine = "";
public bool IsPlayer = false;
public AudioClip _Audio = new AudioClip();
public bool SendMensage = false;
public string MensageName = "";
public PlayerTalkLine[] OtherLines = new PlayerTalkLine[0];
}
[System.Serializable]
public class PlayerTalkLine{
public string DiagLine = "";
public bool IsPlayer = false;
public AudioClip _Audio = new AudioClip();
public bool SendMensage = false;
public string MensageName = "";
public TalkLine OtherLines = new TalkLine();
}
Basically, this is an issue when you have two classes that reference each other. Unity’s serialization isn’t smart enough to know that if A points to B and B points to A that these are the same thing; it serializes it believing that A is a child of B is a child of A is a child of B… it only goes so many levels deep like this, and then it throws up that error message. (IIRC, it’s also not smart enough to know that it doesn’t need to keep digging into a null object, but I don’t think that’s what’s happening here)
The solution that I’ve found (admittedly it’s kind of a pain) is to give each object of one of the classes a unique ID, have each one register itself into a static list or dictionary, and instead of linking to that class, store its ID. You can have a direct reference as a public member or property, but you must use [System.NonSerialized] to make Unity skip over it. I recommend making this a property that, if the cached reference is null, goes to the dictionary and looks up its reference. That way, any code outside these classes won’t have to be changed.