Prefabs holding variables,How to carry accross game objects to prefabs

I’ve made a game where an enemy prefab is spawned and uses an empty game object as its fire point and then rotates toward the player. It instantiates a bullet I made and fires it toward the player. However, the script needs a reference to the player and camera in variable form, so I did that, but whenever I make it a prefab it loses the variable’s value and returns the error: “missingreferenceexception: the variable “player” of (script name) doesn’t exist anymore.” I hope someone can help me.,

HI @EwanRulez369, You’ve just discovered Prefabs do not retain references to other objects. You have to add the references to your null variables after the prefab is instanced.

For example:

   GameObject go = (GameObject) Instantiate( prefab );
   PrefabScript ps = go.GetComponent<PrefabScript>();
   ps.targetTransform  = myTargetTransform; = myCameraReference;
   // and so on....

We’ve all gone through the same thing!