Vanfen
Vanfen

Reputation: 161

Cant display array items in the inspector. Unity

I want to make a class array and see all these classes items in the inspector.

I have 2 scripts. 1 -set to prefab and requires MonoBehaviour to be included. 2 - script where I create the array but in the inspector, I see only Element0, Element1... When I remove MonoBehaviour from the 1st script I'm able to see all the items in the inspector, but that way it doesn't work with the prefab...

1-

[System.Serializable]
public class LevelSetup : MonoBehaviour
{

    public TextMeshProUGUI levelName;
    public Image levelImage;
    public bool locked;
    public GameObject Description;
    public string Text;


}

2-

public class LevelSpawn : MonoBehaviour
{
    public LevelSetup[] levels;

enter image description here enter image description here

Want to be displayed array with all the "LevelSetup" fields (that are public), but if I leave the MonoBehaviour and it works fine with prefab it displays array with the only Element0, Element1, etc. Thank You!

Upvotes: 0

Views: 3701

Answers (1)

DomCR
DomCR

Reputation: 583

When you put a field that inherits from MonoBehaviour the Unity's inspector expects an object that has "Behaviour", so you cannot assign the fields in the inspector because is not interpreted as a regular field.

For example, if you set a Material as a field, and you want to change the color property from the inspector.

public Material mat; //This is actually a class

In the inspector you will only be able to assign a material but you won't be able to access inside the class and change the color.

Upvotes: 1

Related Questions