- Home /
How do I prevent variables being displayed in the inspector BUT not private ?
I want my variables to be publicly available to other scripts but NOT to show up in the inspector. How do I do this? At first I thought it was static but that doesnt seem to work.
static simply means something has no object reference, like ordinary objects. A static class for example can be used from a larger scope but it won't have any relations as parent or child do in object oriented program$$anonymous$$g since it refused to be referenced.
Answer by Proclyon · Nov 17, 2010 at 12:17 PM
or in C# instead of JS
[HideInInspector] public float x = 3.0f;
For the reference from the scripting site you can look here
Another road you could take is using internal as acces modifier. It is in the assembly scope but shows no inspector. But if the only purpose is to not see it in inspector I strongly recommend not doing so.
Answer by Grimmy · Nov 17, 2010 at 12:07 PM
I just found the answer myself on a second search:
@HideInInspector
var myPublicVar = 0;
Howvere any ideas how I would create a block for this rather than writing it for each variable?
eg maybe something like...(but which doesnt work)
@HideInInspector
{
var myPublicVar1 = 0;
var myPublicVar1 = 0;
}
I don't think it exists, the only time I have seen it was in C++ where I had public private blocks in my header files
Too late to the party, but to answer this in general, you can nest a class with fields, instance it through the main class field, and then hide that field with [System.NonSerialized]
For example
using System;
public class Primary {
[NonSerialized]
public NestedFields myFields = new NestedFields();
public class NestedFields {
public field1;
public field2;
}
}
Answer by luislodosm · Feb 17, 2017 at 01:20 PM
Use properties.
public float myPublicVar // It shows in inspector.
public float MyPublicVar { get; set; } // I doesn't show in inspector.
Reference: http://unity3d.com/learn/tutorials/modules/intermediate/scripting/properties
Your answer
Follow this Question
Related Questions
When to use public or private variables for the inspector? 2 Answers
How do you see the private vars in Debug Mode? 1 Answer
Using [SerializeField] vs public 2 Answers
How to properly make a player stats easily editable while keeping them private 1 Answer
Why inpector keeps methods assigned when changed from public to private 2 Answers