How can I enable serialization on a list of objects that reference the next object in the list (so that my list is full of objects that reference each other in a circular fashion)
I am trying to understand why the following does not work:
public class Test : MonoBehaviour
{
public List<ConnectedObjects> test;
}
[System.Serializable]
public class ConnectedObjects
{
public ConnectedObjects nextObject;
public int i = 0;
}
The connected points are intended to point to the next object in their list, and where the last one points back to the start of the list.
Unity does not seem to let me do this. I do not understand why. the public member ‘i’ is editable in the inspector when I populate ‘test’, but not ‘nextObject’. Also, if I populate the list with some code that runs in the editor, the list will never be saved - the references will get broken when I relaunch unity.
Strangely enough, I can have the following code:
public class Test : MonoBehaviour
{
public Test nextTest;
}
where 2 or more Test monobehaviours all reference each other in a circular fashon ( I would set this up in the inspector), and unity will be able to save this just fine.