Search Unity

Prefabs loosing public assigned things

Discussion in 'Scripting' started by pixellegolas, Jun 18, 2018.

  1. pixellegolas

    pixellegolas

    Joined:
    Apr 10, 2011
    Posts:
    223
    Hi!

    I am having a really basic problem that has made me do alot of workarounds to solve.

    I have prefabs with scripts assigned. I have some public values that I drag and drop in editor to fill.

    These prefabs are spawning on runtime but the public fields are always empty. This has given me alot of headache and I have needed to code around this alot.

    Am I missing something basic here? Can't the prefab keep the dragged/dropped public objects?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    prefabs cannot reference other objects from a scene, unless they're within the prefab (i.e. a parent can reference it's child).
     
  3. pixellegolas

    pixellegolas

    Joined:
    Apr 10, 2011
    Posts:
    223
    Ok thanks. Had really issue and did not know why. I dragged objects in public and could not see the problem. But when pausing at runtime and checking prefabs I saw that the publics were empty. I have used FindWithTag instead in the prefab but I see many problems that the prefabs cannot have a drag and drop function