I have a script on a gameObject. That script has a nested list. The problem is: When I make a prefab out of the gameObject, nested lists dont get stored it it. They are empty. I have tried various unity versions. Same Bug. I have this bug in other projects I did google it. No similar results. I did not yet try restarting my pc. (highly doubt that that
ll help)
I did not yet try reinstalling ALL of unity.
I am hoping that I am just dumb and there is a quick and easy solution to this.
If you know how to solve this issue, please comment.
Here are two scripts to replicate it.
#1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
//A nested list that gets removed
public List<List> boolGraph2d = new List<List>();
//Checking if non nested lists get removed
public List intGraph1d = new List();
public void AddToIntList(int what)
{
intGraph1d.Add(what);
}
public void IntCheck()
{
if (intGraph1d.Count == 0)
{
Debug.Log(“LIST IS EMPTY”);
}
foreach (int val in intGraph1d)
{
Debug.Log(val); ;
}
}
public void IntClear()
{
intGraph1d.Clear();
}
public void AddToBoolList(bool what)
{
boolGraph2d.Add(new List());
boolGraph2d[boolGraph2d.Count - 1].Add(what);
}
public void BoolCheck()
{
if (boolGraph2d.Count == 0)
{
Debug.Log(“LIST IS EMPTY”);
}
foreach (List row in boolGraph2d)
{
Debug.Log(row.Count);
}
}
public void BoolClear()
{
boolGraph2d.Clear();
}
}
#2, an editor script for buttons
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(Test))]
public class TestEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
Test scr = (Test)target;
if (GUILayout.Button(“AddSomethingToBoolList”))
{
scr.AddToBoolList(true);
}
if (GUILayout.Button(“BoolCheck”))
{
scr.BoolCheck();
}
if (GUILayout.Button(“BoolClear”))
{
scr.BoolClear();
}
if (GUILayout.Button(“AddSomethingToIntList”))
{
scr.AddToIntList(1);
}
if (GUILayout.Button(“IntCheck”))
{
scr.IntCheck();
}
if (GUILayout.Button(“IntClear”))
{
scr.IntClear();
}
}
}