I have a script that uses Nested Lists in the Editor successfully. Well, almost. No data is retained when you hit Play. So I need to serialize it. Unity doesn’t do this so you have to write a List Wrapper class. I did this but I am getting errors no matter what I try.
How do I get my nested list to serialize and access the data to use in the Editor.
TextureList.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class TextureList{
[SerializeField]
public List<Texture2D> textureList = new List<Texture2D>();
}
myClass.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class MyClass : MonoBehaviour {
[SerializeField]
public List<TextureList> textureObjects = new List<TextureList>();
}
Now, when I try to use the Lists like I did before the wrapper class, it errors. When I loop through the Lists and the Lists inside the Lists I use this:
textureObjects[z]
z loops through wrapper & i loops through nested List
or, it’s supposed to, and did before I wrote the wrapper.
What am I doing wrong here?
Here’s the error:
error CS0021: Cannot apply indexing with [] to an expression of type `TextureList’
This seems to be telling me that I don’t have a nested list because if I remove and leave [z], it works. However, then more errors occur down the line and I need to have a nested list, not just a list.