- Home /
Editor tool/serialization crash on windows
I've encountered a very strange problem that I can't seem to find a solution too. However I suspect that it's an issue related to serialization, or perhaps even a bug in Unity itself.
I have an A-star based pathing system, and in order to quickly create pathing graphs I've written a simple tool to connect nodes. The nodes are basically just game objects with a simple script that contains a list of references to other node objects. My editor tool takes all the nodes (called Cookies) in the current selection and attempts to connect them to eachother. To save the changes it makes, I'm calling SetDirty on the node object after modifying its edges.
The thing is, that it seems to work just fine. And in fact, it works just fine on my machine (running OSX), but some scenes just crash the unity editor when they are loaded by my teammates working on windows machines. I haven't got a crash log atm, but from what I could tell there was not really any information about what went wrong.
If I load up the corrupted scenes (on osx) and remove all the node objects, the other guys can load the scene again. Crash occurs when opening the scene in the editor or attempting to load it using LoadLevelAsync.
public class NodeTool
{
[MenuItem("Pathing/Connect Nodes %g")]
public static void InterconnectNodes()
{
var cookies = new List<Cookie>();
foreach(var obj in Selection.gameObjects) {
var cookie = obj.GetComponentInChildren<Cookie>();
if (cookie != null)
cookies.Add(cookie);
}
Debug.Log(string.Format("Connecting {0} cookies", cookies.Count));
foreach(var cookie in cookies) {
foreach(var other in cookies) {
if (cookie == other)
continue;
cookie.Connect(other);
}
EditorUtility.SetDirty(cookie);
}
}
}
And the actual cookie class:
[Serializable]
public class Cookie : MonoBehaviour
{
[SerializeField]
public List<Cookie> Edges = new List<Cookie>();
public void Connect(Cookie other) {
if (!Edges.Contains(other))
Edges.Add(other);
}
}
(I added the serialization attributes recently, but they don't seem to make any difference what so ever)
Any ideas would be greatly appreciated! Thank you :)