I made a custom class which I assign to a gameobject, it has a couple of parameters, one of them of type List < List < Transform > >.
Now the problem is that it seems to lose this data as soon as I reload the scene.
whereas a List < Transform > still contains all its data.
also, all parameters are shown in the inspector, including the List < Transform >, only not the List < List < Transform > >.
Is this by design?
How do I avoid this?
1 Answer
1
Newer Answer
I don’t believe that Unity will serialize a two dimensional list. You can create a small serializable class that only contains a list of transforms. then you have a list of classes that each contain a list of transforms.
public class ClassA : MonoBehaviour
{
public List<TransformContainer> containers;
void Start ()
{
}
void Update ()
{
}
}
[System.Serializable]
public class TransformContainer
{
public List<Transform> transforms;
}
Original Answer
It depends on what datatype your list is storing. You can store classes in your list and have them serialize, or object references.
also, you need to make sure the list is public.
If you are storing custom classes, try this:
[System.Serializable]
public class ClassToStore
{
public int ID;
public string name;
}
public class StorageClass : MonoBehaviour
{
public List<ClassToStore> storage;
void Start()
{
// check storage in some way
}
}
code test
public List<List<Transform>> transforms;
works for me.
it can depend on what type you're storing in your list. for example, I ran into a problem some time ago where I was attempting to store a List of System.Type. Unity won't serialize System.Type, so I would always lose my stored list. Another workaround is to create a custom class that stores your information, and have it inherit from ScriptableObject
– zombienceI actually typed what type of list it was, but apparently anything between < and > gets deleted automatically. I'll fix my post. The type that doesn't get remembered is List < List < Transform > >
– Steven-1make sure you hit the code button. adding characters like "<" might be interpreted as HTML and be removed from your post
– zombienceok, I just fixed it, but for some reason it still shows the previous version? edit: fixed again. I added spaces because it still gets removed otherwise, even when within code tags
– Steven-1