Is there any way of creating a public variable that doesn't show up in the inspector? We are currently working on a huuuge array (literally thousands of cells in it) and it works perfectly except from the fact that Unity's inspector tries to display it and crashed on a very regular basis.
The problem is that we need to make this variable public in order to have other scripts access it freely. But we cannot find a way to make the inspector ignore it.
We get the error message "too many heap sections" which means that somehow, somewhere Unity tries to sort the data and runs out of memory. We do not need to look at the data, so we'd like to NOT show it if possible.
BTW, when we close the inspector, Unity doesn't crash. That's how we know the source of the problem.
The attribute HideInInspector might be of use, as well as NonSerialized if you don't want the values of the variables to be saved with the scene.
Note also that in general at least, it's not necessary for a variable to be public in order for it to be accessible from outside a class/struct. (In C#, for example, it's common to use properties to facilitate controlled access to protected or private data.)
wow, super! I think this may be what we're looking for. Really appreciated!
Is there a way to have a number be NonSerialized and still be visible in the editor? I'm working on a script that I need to monitor how a variable changes, but I need for it to clear and be assigned a new value when the scene starts. It's based on the time of day, down to the second. Currently, when I first attach the script and launch the scene I assume it serializes the number because it never changes after that.
I think this is a better solution for when you set the value from another script:
[System.NonSerialized] public int valueOfSomeThing;
Since it avoids bad data being stored in the scene.
[HideInInspector] still works but the above should solve the more recent complaints of the original script not working eight years after the original answers were given
This comment is four years late, but yes. You can indeed write the code like that. It will not cause any serious problems. Its the same code but behind instead of before.
Very useful! Since this is very much specific to the Unity platform, we didn't know this feature existed. Thanks!
– ilkejavWow... this is just what I was looking for and it's a shame I cannot vote up.
– pctrollFor Javascript it is like that: var notHidden: float; //Displayed @HideInInspector // Hides var below var hidden: float;
– cgeopapaQuite helpful! Thank you.
– AO7