Serializtion Depth problem

Oh Unity, why do you hate me so so much?

so I’ve just encountered the infamous serialized depth exceeded problem, hooray.

My structure is:

  • Main Object
  • List of Sequences
  • List of Channels
  • List of Keyframes
  • List of Objects

Sequence contains Channels
Channels contain Keyframes
Keyframes contain Objects

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. :expressionless: 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.

Anyone have any ideas?

Thanks

That one shouldn’t produce an issue as far as I can see. Are there other variables in Sequences, Channels, Keyframes or Objects, that are serialized?

yes. And Sequence, Channels, Keyframes and Objects all extend a abstract base class.

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.

ah you’re right. Within Object, I was storing a reference to a GameObject prefab :expressionless:

guess I can change that to an asset path instead.

Thanks.

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.

hmm, what if the GameObject contained a component that somehow created a circular reference?

Maybe I can create a list of GameObjects in a master list, and have the “Object” point to that object by an index.

setting the GameObject reference to NonSerialized has solved the issue, so I can only assume something in that GameObject is causing a problem.

when I put the Serialized attribute back on I get this error:

Serialization depth limit exceeded at ‘KeyObject’. There may be an object composition cycle in one or more of your serialized classes.

ok, I’ve made a barebones test. *Attached unity package.

  1. Open up TestScene
  2. Add “MainObject” component to “MainObject” in scene.
  3. 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.

1726430–108882–serializationError.unitypackage (6.01 KB)

interesting, opening in Unity 4.5.2p3, no errors…

That’s interesting, because non of the patched seems to have a resolution for that. I am going to check the unitypackage later on.