How can I fix this issue? There are no circular references, it seems Unity thinks that I’m just creating endless Lists. But no, I’m not. If I remove the Channels list I get no max depth exceeded.
One solution might be to create LinkedLists instead of Arrays. Giving each object a pointer to the next object.
Another possible, more ugly solution, is to create a master list of all Sequences, Channels, Keyframes and Objects in MainObject. Then, within each Sequence, Channel and Keyframe, create an index array which holds the indexes of its child elements within the master list. So that when a Sequence, Channel or Keyframe is deleted, the elements they contain are also removed. This seems like bug city though, when deleting elements from an array, EVERYTHING must be re-indexed.
It is very likely that you produce a cycle with those other variables. If it is possible to not serialize them, you should consider that in order to avoid circular dependencies for the serialization.
If you are storing a reference to something of type GameObject, it shouldn’t be a problem.
I am just blindly guessing here. You either need to show the code or you can start another project where you step by step add variables for the serialization to see where exactly the issue happens.
ok, I’ve made a barebones test. *Attached unity package.
Open up TestScene
Add “MainObject” component to “MainObject” in scene.
Observe the errors.
*Open in Unity 4.5, no errors in 4.3
The very strange thing here, is that the first time you open unity, add the component, I get the errors. If I then destroy the object and make a new one, no errors. Close unity, re-open, errors appear.