Inspector: show our own classes

Hey.

I was wondering how I can show my own classes in the inspector ?

I have a simple class (called “Character”) which is a component of a GameObject. I have another one, called “Characteristics”, with 4 float variables. “Character” has a Characteristics variable and I would like to edit the 4 variables from the inspector…

public class Character : MonoBehavior {
    public float speed = 0f;
    public float otherVariable = 0f;
    public Characteristics characteristics = new Characteristics();
}
public class Characteristics {
    public float var1 = 0f;
    public float var2 = 0f;
    public float var4 = 0f;
    public float var5 = 0f;
}

I can edit “speed” and “otherVariable” from the inspector but I can’t edit the variables from Characteristics… I’m pretty sure I can do that but how ?

Thank you :smile:
Sbizz.

you should use the System.Serializable attribute, so it can be serialized into the inspector, your code should be like this

[System.Serializable]
public class Characteristics {
    public float var1 = 0f;
    public float var2 = 0f;
    public float var4 = 0f;
    public float var5 = 0f;
}

Thank you very much :smile:

Sbizz.

1 Like