[C#] Not seeing class in inspector

Hi All,

For some reason I’m unable to see my class in the inspector. Not sure why.

using UnityEngine;
using System.Collections;

public class tes : MonoBehaviour {

   // Trying inside the main class
    [System.Serializable]
    class Test
    {
        public int p = 5;
        public Color c = Color.white;
    }

}

// Trying outside the main class
[System.Serializable]
class Test
{
    public int p = 5;
    public Color c = Color.white;
}

Your public class has nothing in it for the Inspector to show.

Your inner Test class is both hidden (private by default) and not a MonoBehaviour. I don’t think you can see inner classes anyway.

Your outer class is similarly not a MonoBehaviour.

There’s nothing here for the Inspector to see.

Here’s a modified script, which is still not working.

using UnityEngine;
using System.Collections;

public class tes : MonoBehaviour {
    [System.Serializable]
    class Test
    {
        public int p = 5;
        public Color c = Color.white;
    }

}

[System.Serializable]
public class Test : MonoBehaviour
{
    public int p = 5;
    public Color c = Color.white;
}

Each file can only show a single MonoBehaviour in the inspector. What I think you’re meaning to do is create an instance of your Test class inside of your tes class.

I’m aware of only one monobehaviour allowed, was just showing angrypenguin that it would produce the same results.

Yes I’m trying to create an instance of Test class inside of the tes class. I’ve done this many times before of course, but I’ve blanked out. I’m half asleep trying to make this thing in the middle of the night :slight_smile:

public class tes : MonoBehaviour {

   public Test test;    // <----- this line here

   // Trying inside the main class

    [System.Serializable]

    class Test

    {

        public int p = 5;

        public Color c = Color.white;

    }

 

}

 

// Trying outside the main class

[System.Serializable]

class Test

{

    public int p = 5;

    public Color c = Color.white;

}

Line #3

That’s what I was looking for. Can’t believe I forgot this step. Thanks.