Bug report: Reference to a GameObject placed in a prefab becomes NULL

Forums 💬 FlowCanvas ⚙️ Support Bug report: Reference to a GameObject placed in a prefab becomes NULL

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #22935
    pawels
    Participant

      How to reproduce:

      1. Start the editor.
      2. Create a prefab GameObject.
      3. Add a bound FlowScript to the prefab.
      4. In the FlowScript of the prefab, create a reference to an object existing on the scene (for example by dragging the object from the hierarchy view to the FlowScript).
      5. Create a variable of type GameObject in the prefab’s blackboard, and set its value to an object existing on the scene.
      6. Save & restart the editor.
      7. Now the object reference in prefab becomes NULL, and the variable becomes None (GameObject).

      #22938
      Gavalakis
      Keymaster

        Hey,

        This is natural and is completely a Unity limitation.
        In Unity, assets (which includes prefabs not placed in the scene), simply can’t have references to scene objects. There is really nothing I can do about this Unity limitation unfortunately. I know it can get frustrating when you start out with Unity.

        The typical workarounds to this, is that you use some of the Find unity static methods, like GameObject.Find, GameObject.FindWithTag or Object.FindObjectOfType for example.

        Let me know if I can help you further with this.
        Thanks.

        #22937
        pawels
        Participant

          Thanks for letting me know. I’m in the process of learning Unity, its advantages and limitations.

          I found another workaround: I can create a GameObject variable on a global blackboard, set its value to a scene object, and then use that variable in prefabs.

          #22936
          Gavalakis
          Keymaster

            Thats a very valid workaround as well, yes 🙂

          Viewing 4 posts - 1 through 4 (of 4 total)
          • You must be logged in to reply to this topic.