Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Cross-Scene References Drag and Drop callback in custom inspecotr?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Xarbrough, Jul 24, 2017.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    A few Unity versions ago it was possible to drag a GameObject from a different scene into an Object fields on my component. The reference would not serialize of course, but I could still use the Unity Drag and Drop behaviour and then serialize manually through my custom inspector.

    Sometime along the road, Unity disabled the feature to drag references from one scene to another to prevent corrupted scene files, but now my tool doesn't work anymore, because I can't drag Objects into the field.

    Is there any simple way to replicate the previous behaviour? I'd love to just drag any GameObject from any scene and determine, if it needs to be serialized in my custom way, if it's from another scene.
     
  2. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    823
    I noticed that it is possible if you use Odin inspector, but I guess it is not on purpose that it is possible.
     
  3. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Yes, I saw the feature in different asset store products as well, so I looked more into it.

    After some more research I found the answer: Unity actually added the functionality back in, I just didn't notice it: https://docs.unity3d.com/ScriptRefe...SceneManager-preventCrossSceneReferences.html

    In my custom inspector I can set the flag to allow cross scene references without them throwing warnings. Then I can serialize the data to my own reference system and voila.
     
    Johannski likes this.
  4. waheyluggage

    waheyluggage

    Joined:
    Aug 22, 2015
    Posts:
    15
    Hello, I'm looking to do something similar to this, was wondering if there's any docs\tutorials\examples that you know of I can take a look at please? Thanks