- Home /
How to get variables of the script show in unity editor/inspector?
How to get variables of the script show in unity editor/inspector?
Answer by reissgrant · Jan 31, 2011 at 03:10 AM
If variables are declared "public" they will show up in the inspector.
Thanks everything alright, error in scripting was the cause
Note that private fields will also show up (read only) when Inspector is set to "Debug" from the little drop down menu in the upper right. Handy for looking at what's going on inside your scripts.
Answer by Nicholas Rishel · May 11, 2014 at 11:18 PM
[SerializeField] before the variable will make it visible in the editor. You can do this to make private members visible and is usually preferable.
Hey, I know this question and answer is ages old but. This sounds to me like the better solution than declaring the variable public, isn't it? I mean I see everybody is using public variables to edit them in the editor. And also the Unity Documentation says on [SerializeField]: "You will almost never need this." Which makes the impression to me that Unity wants me to declare variables, I want to edit in the Editor, public. But this means like zero encapsulation. Is this some kind of a new trend in program$$anonymous$$g?
You're pretty much on point; Serialize Field is used to encapsulate variables in a script you want visible in the editor but not visible to other scripts. It's considered better practice even if not encouraged by Unity Technologies, and shouldn't have any negative consequences.
Your answer
Follow this Question
Related Questions
Edit child in parent list [Custom Inspector] 1 Answer
Custom Transform Editor in Scene Editor 2 Answers
Player damage stops working over time 0 Answers
Custom tab of Terrain inspector, is it possible? 0 Answers
How to get notification of moving a GameObject in the hierachy when editing the scene? 1 Answer