Hi there,
Has anyone else had issues with the json data for the elements of an embedded graph in the Unity scene file being in a different order when the scene is saved? It’s causing a bit of a pain for us in merging changes.
I’m trawling through the serialization code to try to find a solutions. Just wondering if anyone else has come across this and if there’s a workaround for it?
Thanks!
Rob.
OK, I think it’s down to the elements being sorted in the deserialization code by dependencyOrder, which is generally a low number shared by a lot of elements (i.e. loads of elements will be 0, loads are 1 etc.).
I think a solution is to change the OnBeforeSerialize function in graph.cs to sort them into a consistent order. I’ve chosen to do it by dependency order and then by guid. i.e:
public virtual void OnBeforeSerialize()
{
_elements.Clear();
var sortedElements = ListPool<IGraphElement>.New();
foreach (var element in elements)
{
sortedElements.Add(element);
}
sortedElements.Sort(CompareElements);
_elements.AddRange(sortedElements);
}
private static int CompareElements(IGraphElement a, IGraphElement b)
{
int dependencyComparison = a.dependencyOrder.CompareTo(b.dependencyOrder);
return dependencyComparison != 0 ? dependencyComparison : a.guid.CompareTo(b.guid);
}
I need to give this a LOT of testing. If anyone can see a problem with it, please let me know!
Rob.