A better persistence mechanism

I found a few bugs with rearranging objects in the hierarchy (version v1.11).

The reason for these bugs was primarily in the way I kept track of the container’s child order. This has originally been done by using GUIDs (unique identifiers for each component adapter).

The GUID for each adapter has been generated the moment the component adapter was added to the scene. The container then kept the list of the child GUIDs, and that list had to be updated each time the component is added or removed from the parent, or changed its order.

This also had to persist after the Play mode is stopped, so the list has been kept in the memory, re-read after the play mode is stopped, and then re-applied to adapters in the scene.

There was the GUID utility taking care that all the GUIDs in the scene are unique. If the already existing GUID found, it was automatically re-generated. And the parent container list had to be refreshed too.

Clearly, this has been a very complicated process, and I’ve looked for the ways to drop the GUID thing altogether. Finally, I managed to make it work.

No GUIDs means that no prefabs are being inspected and then rewritten by the mentioned GUID utility class (this has been breaking the prefab connection the moment the same prefab had two or more instance in the scene).

Keeping the linkage to the original prefab means: you will be able to change a single prefab instance (its children, order of the children etc.) and apply changes to all the other prefabs (which is nice and what we all expect when working with prefabs) :)

Since the persistence thing became very complicated, I had to write my own debug window, which displays the “true” hierarchy – with both the nesting and ordering information, and also the adapter InstanceIDs. By using the debug information, I was finally able to track down and fix the weird corner-cases of ordering information not being refreshed properly (on child list reorder, parent change etc).

Additional debug window displaying a true component hierarchy

Additional debug window displaying a true component hierarchy

Posted in News