- Home /
What is the name of/How do I use the box in the Script Inspector that allows you to assign values to Public data?
The box in question is the one in the picture that contains Room Prefab, Item Prefab, etc. A Script's public variables appear there. I can assign whatever values I want to just the script. This way when I assign the script to an object or prefab those values for that instance are automatically populated. But this only works when I assign the script in using the editor itself (not at run-time).
When I use AddComponent it does not automatically populate those values though. All of the values remain null and then I have to load all of the prefabs in code and it creates a nightmare of loading prefabs and passing them around unnecessarily. Can I use the information in this box dynamically?
I only ever need to assign these variables once so I have no reason to touch them at all in code.
I have no idea what it is called so I can't google how to use it dynamically (Since I am hoping to use AddComponent). The Unity Manual doesn't describe this box specifically as it only discusses Objects and not scripts.
While typing this I came up with a solution that I don't like.
I could just use some conditionals in the script to prevent it from initializing anything until I am ready, then I will be free to avoid using AddComponent altogether eliminating my problem. But knowing the name of the box is still something I would like to know for future use in case I am required to use AddComponent elsewhere in a similar situation.
Answer by Bunny83 · Dec 07, 2012 at 10:31 PM
The "Default References" ( that's their name ;) ) are an editor only feature as far as i remember. This information isn't available at runtime. It's actually the same for prefab connections. At runtime you can't determine from which object another object has been cloned.
If you need to store prefab references, Just attach the script to a GameObject in the scene. There it will be serialized and you have your references available at runtime.
Answer by shane.rachel · Dec 07, 2012 at 09:56 PM
the circle next to (NewRoom, Item, Chest, etc.) click on it and you can assign prefabs to those variables. Of course you need to create the prefabs first.
The box has no specific name, it's just a part of the inspector that stores public variables. Unity considers this to be pretty straightforward which may be why you can't find info on it
Sorry I wasn't specific enough. I wanted to know if I could use it dynamically. I know how to use it directly in the editor.