Search Unity

My prefab will not accept references

Discussion in 'Scripting' started by zlong1, Oct 16, 2018.

  1. zlong1

    zlong1

    Joined:
    Sep 7, 2018
    Posts:
    4
    I have an object called "HealthPowerUp" that I created. Its scripts are all attached and it otherwise functions as Intended. (following image)



    I am trying to make it a prefab so I can spawn it. When I drag it into the prefab folder it creates the prefab, but none of the references (Player Health, Pickup Effect, Health Slider) are attached (following image). I try to drop them back onto the prefab, but I am unable to do so for Player Health or Health Slider.



    Does anyone know what I might have done wrong?

    This is the object's script.


     
  2. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    813
    Those inspector screenshots are impossible to look, so I will take a guess here and say that you are trying to set a scene reference to the prefab.

    You cannot set a scene reference to a prefab since that reference only exists when the scene is active. You will have to set those reference when you spawn the prefab (if you are spawning it by code) or after dragging it to a scene.