- Home /
Question by
MysteryPyg · May 10, 2017 at 08:30 PM ·
gameobjectinstantiateprefabinspectorinheritance
Prefab not inheriting GameObject when instantiated
I have a prefab with a script attached, and the script needs a GameObject to be dragged in through the inspector. When I instantiate the prefab, the GameObject is no longer assigned to the clone. Have I made a stupid mistake, or is this supposed to happen?
Comment
Answer by tanoshimi · May 10, 2017 at 08:32 PM
That's supposed to happen: prefabs can't reference objects in the scene hierarchy. Instead, you need to grab a reference to the gameobject in the Start() method of your prefab after it is instantiated.
Your answer
Follow this Question
Related Questions
Unity not Instantiating as Prefab 1 Answer
Instantiated Object being auto-deleted 0 Answers
How to instantiate within GameObject 1 Answer
Prefab variants inherited scripts 1 Answer
autolink to prefab? 0 Answers