[SOLVED] Fields do not shown up in inspector (class inherits from a Unity Script)

Hey!

I tried to do a script that extends some functions of an existing script but I’m currently blocked on something stupid and I have no idea why it does that.

The script can not be more simple :

public class UIContentSizeFitter : ContentSizeFitter {
    public float m_MaxHeight;
    public float m_MaxWidth;
}

Yes. Only that. :stuck_out_tongue: I want these variables to be accessible from the inspector and I have no idea why they just don’t shown up…

Any idea ?

Thank you :slight_smile:

The parent class needs/must inherit from MonoBehaviour

Parent Class

```csharp
**using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour
{
[Header(“Variables From Parent Class”)]
public string Text;
public int Int;
}**
```

Child Class

csharp** **using UnityEngine; using System.Collections; public class TestmyTest : Test { [Header("Varibale From Child Class")] public string TestMyTest; }** **

Result Using Unity5:

You need to inherit from MonoBehaviour.

You can also inherit from UIBehaviour, your variables are going to be shown inside the Inspector.

ContentSizeFitter inherits from UIBehaviour…

public class UIContentSizeFitter : UIBehaviour {
    public float m_MaxHeight;
    public float m_MaxWidth;
}

This works.

1 Like

UIBehaviour inherits from MonoBehaviour. Are you saying you’re still unable to see your public variables in the inspector?

Okay, found the issue…

There is a ContentSizeFitterEditor and it doesn’t call DrawDefaultInspector. So it only shows what the script ContentSizeFitterEditor wants…

So I created my own script too…

[CustomEditor(typeof(UIContentSizeFitter), true)]
public class UIContentSizeFitterEditor : ContentSizeFitterEditor {
    public override void OnInspectorGUI() {
        DrawDefaultInspector();
    }
}
3 Likes