- Home /
How can I link a GameObject instance to a script variable in a Prefab using the editor?
I have an enemy that is supposed to track the player. I can drag the player instance to the target variable on an instance of my enemy's script but as soon as I make my enemy a prefab, the link is broken. I can then drag the player prefab (but not the instance) to the enemy script, but the enemies then target the prefab at 0,0,0. Is there a way to assign the player instance to the script variable on the prefab?
I'd like to avoid finding the player instance using code since I want to apply this method in other similar situations such as referencing the player instance from a UnityEvent on a prefab pickup script that should be more generic than just grabbing the player instance.
Answer by SingularDeviation · Mar 19, 2015 at 03:19 PM
As far as I know it is not possible to assign instances to prefabs.
Imagine creating a new scene and placing the prefab in that scene. The prefab would still be referencing an instance of the player, but the instance does not exist!
Your answer
![](https://koobas.hobune.stream/wayback/20220613190618im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to modify prefab permanently via script. 0 Answers
changing a bool in a prefab doesn't change in it's instance. 2 Answers
How Mark Prefab Dirty? 1 Answer
Changing a prefab's name (via the editor) doesn't apply the new name to the prefab's instances? 1 Answer
Trying to have my Editor Script save the changed settings when I hit Play 0 Answers