- Home /
Why is my class hidden in inspector with C# and not JS?
I used to code in JS (with Unity at least) and I recently decided to go for C#. In JS, when you create a class and use it in a monobehaviour, it's shown in the inspector, with a little arrow to unfold, but apparently not in C#. The code below explain the matter :
JS code (I can see "classVar" in the inspector, and "varNotHidden" within it)
class SecondClass { var varNotHidden : int = 0; @HideInInspector var varHidden : int = 0; }
class MainClass extends MonoBehaviour
{
var classVar : SecondClass;
}
C# code (I can't see "classVar" in the inspector)
using UnityEngine;
public class SecondClass {
public int varNotHidden = 0; [HideInInspector] public int varHidden = 0; }
public class MainClass : MonoBehaviour { public SecondClass classVar; }
So I wonder why "classVar" remain invisible in C#. Both variable and class are public, I'm not using [HideInInspector] for it. I'm kind of lost ...
Is there something like [PrettyPleaseDontHideInInspector] ? I really hope I don't have to use a CustomEditor for each class ...
Answer by Peter G · Jan 23, 2011 at 01:11 PM
You have to add the [System.Serializable]
attribute to your class in C#.
[System.Serializable]
class someClass {
public int thisValueWillBeDisplayed;
}
Your answer
Follow this Question
Related Questions
Is it possible to create a script dinamic like animation>size controling the Elements variables? 1 Answer
Javascript and C#, different behaviour in inspector ? 1 Answer
Need health to decrease with movement in Javascript 1 Answer
How would I be able to subtract from a variable when it hits something? (OnCollisionEnter) 1 Answer
Adding varibales from other scripts 3 Answers