public class GameManager : MonoBehaviour
{
public List<List<GameObject>> m_SlotList = new List<List<GameObject>>
{
new List<GameObject>(),
new List<GameObject>(),
new List<GameObject>(),
new List<GameObject>(),
new List<GameObject>(),
};
void setList()
{
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 10; j++)
{
m_SlotList[i].Add(new GameObject());
}
}
}
void Start(){
setList();
}
void Update(){
Debug.log(m_SlotList[0][0]);
}
}
When this program starts running, it returns “new GameObject” as log. But when I type m_SlotList [0] [1] in
c # while running Unity, it returns an “ArgumentOutOfRangeException” error. What is the reason of this?
If there is no solution to this, how can I edit the nested list in Inspector?
Because this is not about code, this is about hot reloading. You hadn’t made that clear in your original post that you talk about hot reloading. When you change code while the game is running, all of your code needs to be recompiled. When this happens everything on the managed side is destroyed since the whole C# appdomain is destroyed and reloaded.
When this happens Unity will serialize all objects currently loaded, destroyed the appdomain, compiles the new code and restores the previously serialized objects. However that means only things that can be serialized will survive the assembly reload. Since Lists of Lists are not serializable by the Unity serializer your list will be lost after the reload because Start won’t run a second time.
I recommend reading through the script serialization documentation, especially the hot reloading section and what kind of data can / can not be serialized.