- Home /
Why are variables assigned through the inspector considered not assigned when prefab is spawned?
I have a prefab to which I assigned a script. In that script, I defined public variables and I assigned them through the inspector. Then I clicked "Apply" to the prefab.
However, when I spawn that prefab, it says the "variable has not been assigned".
Are there any reason why that would happen? Thanks in advance
Answer by Bunny83 · Jun 27, 2014 at 12:41 PM
Prefabs are assets. As such you can only reference other assets in the project. You can't reference objects in a scene since they aren't assets. If an instantiated prefab needs a reference to another object in the scene, you have to set it when you instantiate the prefab.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to change variables from a script in another scene? 1 Answer
Change global variable on input first than following scripts 0 Answers
Having a script variable update between two objects 1 Answer
Script References Exploration 0 Answers