- Home /
Assigning variables in inspector
What happens when I assign a MonoBehaviour Object variable via inspector? Is it instantiated on game start with active being set to false? If not is there a way to mimic inspector variable assignment in script?
The object go is a null then, when I try to use any of the class methods.
You misunderstood my question, there is no error in my code. I wanted to ask how unity works. What is the script (c#) reflection of assignement of public variables via inspector (when you drag object to a spot). When I assign GameObject this way, it is not created in scene, but I can access its funcionality. I believe GameObject.Find searches the scene for object with exact name, also it avoids non active GameObjects. Assignements allow me to do anything I want with given variable, without creating an instance, how to do that in script?
Answer by Eric5h5 · Sep 28, 2014 at 05:10 PM
Nothing happens when you assign an object to a variable in the inspector, aside from the variable now containing a reference to that object. No instantiations or anything occur. There are various ways of getting references in code, such as GameObject.Find, FindObjectOfType, Resources.Load, etc.
Your answer
![](https://koobas.hobune.stream/wayback/20220613163948im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Refering to gameobject script is attached to 1 Answer
My marble (Player/Gameobject) goes through the "play board" (gameobject). Why? 1 Answer
Two exact objects behaving differently... *scratches head* 0 Answers
C# GetComponent / change values throught other script 3 Answers
How to create GameObject without adding it to scene? 1 Answer