A Monobehaviour can have references to GameObjects in the same scene, but Prefabs, ScriptableObjects can't reference GameObjects in a scene. While Assets, Objects and serialization covers references to assets, i.e. actual files, it doesn't explain how references to scene objects work. But it has to be some kind of serialization, for example, do they also consist of a GUID part and a local id part when serialized?

  • \$\begingroup\$ Have you tried setting your editor serialization mode to "Force Text" then opening up a scene file in a text editor to see for yourself? \$\endgroup\$
    – DMGregory
    Mar 19 '19 at 4:30
  • \$\begingroup\$ Thanks, I didn't realize a scene was also a text file in that mode. So in this case a scene is an asset, and a "fileID" that identifies a game object is the local id mentioned in the doc? Then I think there is no reason that a prefab can't find an object in a scene, it's just the design decision that a prefab can't contain such references? \$\endgroup\$ Mar 19 '19 at 9:02
  • \$\begingroup\$ No. A prefab can be used in any scene, even if the scene it wants to reference isn't currently loaded. In such a case, if it were allowed to reference a scene object, that reference would break because that object doesn't exist in any currently loaded scene. \$\endgroup\$
    – DMGregory
    Mar 19 '19 at 10:22

You must log in to answer this question.

Browse other questions tagged .