I have a typical struct and a typical call for it. But I have no idea how to add an empty item to the list, when the list itself is empty (not even appearing).
public struct XYZ {}
public class AAA : MonoBehaviour {
public List<XYZ> CBA;
void Start() {
//CBA = new List<XYZ>();
}
None of them appear in Inspector. I don’t know how to add an item. I need it to appear in Inspector so I can add elements with far less mess and link them into slots.
List work just fine in the inspector, just make sure you add the System.Serializable to the struct, then when the script is added to a GameObject, you can then see the list and change the size and add values to the elements.
[System.Serializable]
public struct XYZ
{
public string aString;
public float aFloat;
}
As an extra note never make Lists public available for encapsulation reasons.
IEnumerables could be fine, but most often you want to abstract such things and have public methods that makes sense for what problem the class encapsulate