- Home /
How to: c# public variable not show up in the Inspector?
Getting up to speed on c# and Unity....
In c# is it possible to declare a public variable but not have it show up in the inspector?
I want to do this for public variables that will be set by external scripts and have no need to be in the inspector so I don't want the inspector to be cluttered by them.
Answer by ncallaway · Jan 05, 2014 at 03:26 AM
Public properties won't show up in the inspector.
public class QuickExample : MonoBehavior
{
public float MemberVariable; // this shows up in the inspector
public float Property { get; set; } // this doesn't show up in the inspector
}
Other code can refer to properties in a manner very similar to accessing public variables.
QuickExample test = new QuickExample();
test.MemberVariable = 5;
test.Property = 6;
Debug.Log(test.MemberVariable); // logs "5"
Debug.Log(test.Property); // logs "6"
I encourage you to read up about C# properties, as they're a very handy tool that C# provides: http://msdn.microsoft.com/en-us/library/x9fsa0sw.aspx
Your answer
![](https://koobas.hobune.stream/wayback/20220613125559im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Using [SerializeField] vs public 2 Answers
Cannot assign Public GameObject variable in Inspector... 2 Answers
Set number of public objects through the inspector 1 Answer
Public "char" parameter not showing on inspector? 2 Answers
i cant drag my image in the inspector when i use the code public image how can i fix this 1 Answer