- Home /
public variables not displaying in inspector
I am declaring public variables that are not being displayed in the inspector. I am trying to assign a prefab to a public GameObject. Is there a way to do that in the script?
Is the variable a property? You can't display properties in the inspector.
I have a
public float gameSpeed;
this shows up in the inspector;
I then have
public GameObject ObjectPrefab; public float objectSpeed;
neither shop up in the inspector.
To elaborate on asimov's answer, if there are compile errors then new variables you add won't appear in the inspector until you fix those errors.
Answer by No_Username_Found · Jun 04, 2014 at 04:01 PM
I realize this is an old question, but I stumbled across this while trying to resolve it on my machine. As it turns out, in Unity4 public static variables do not appear in the inspector. When I changed them to non-static variables, they showed up like I expected.
I'm curious why this is, of course. I'm new to programming and don't see the logic.
static variables can't be assigned in the inspector because they represent 1 variable across all instances of the script. so if i had two game objects with the same script on and they both had different static variables definitions in the inspector, the engine wouldn't know what to use.
public variables are much different, in fact I've never heard of a "static public" variable before, but the above reason is probably still the answer.
Your answer
Follow this Question
Related Questions
Calling individual variables from individual scripts 1 Answer
Setting public GameObject to a different Prefab through code 0 Answers
How do I reassign a public variable on an instantiated object? 1 Answer
How can I reference in a prefab's script a gameObject found in the scene 1 Answer
Invisible Public Variable in Inspector 5 Answers