Search Unity

Cannot drag a gameObject which is in hierarchy to a reference in prefab?

Discussion in 'Prefabs' started by unity_94d33m, Mar 18, 2019.

  1. unity_94d33m

    unity_94d33m

    Joined:
    Sep 11, 2018
    Posts:
    20
    This pic will tell the story: ( Direct Pic links never work for me so I put URL link below )

    https://imgur.com/a/yjRV3b3

    Edit: Realised I could drag the prefab into hierarchy and then set the references. But no use since instantiating the prefab will remove the references, and I have to use .find. Any better way to set references or is this ok?
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    You cannot reference objects in the scene from a prefab, so you'll have to assign those when you instantiate it.

    .Find is probably not the correct way to do this. The object that spawns the prefabs could know about the references it needs, or you can have some singleton container for the references, depending on what you need.
     
    unity_94d33m likes this.