Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

GraphView - How can I drag an object out of an object field?

Discussion in 'Scripting' started by DanVioletSagmiller, Aug 24, 2022.

  1. DanVioletSagmiller

    DanVioletSagmiller

    Joined:
    Aug 26, 2010
    Posts:
    203
    I'm building a custom GraphView for AI in my RTS, and I'm looking for a solution to drag elements OUT of the graph view. I can drag Scriptable Objects into fields on the nodes of the graph view, but I cannot drag them back out to put into parameters of other objects. Example:

    upload_2022-8-23_21-3-41.png

    The key issue, is that while the graphview can reference ScriptableObjects that are saved as files, I'm planning on it producing ScriptableObjects that are not associated with files. See this code:

    Code (CSharp):
    1.         soField = new ObjectField
    2.         {
    3.             objectType = typeof(BooleanObservable),
    4.             name = "b2",
    5.             value = new BooleanObservable()
    6.             {
    7.                 name = "Boolean Test",
    8.                 Value = true
    9.             },
    10.         };
    11.  
    12.         soField.RegisterValueChangedCallback(v =>
    13.         {
    14.             node.BooleanObservable = soField.value as BooleanObservable;
    15.         });
    16.  
    17.         node.mainContainer.Add(soField);
    As you can see, when it sets up the field (line 5), Value = new BooleanObservable()... it is generating that scriptable object in memory only, and not saving it to a file. I'm hoping for a way to reference that in a different selected game object. (as shown in the picture)

    Any ideas if it is possible, or even alternative approaches?
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,882
    As graph view and the graph tools foundation are UI toolkit based, questions like these are probably better suited to the UI Toolkit subforum.

    Nonetheless, there's a page in the documentation about supporting drag and drop: https://docs.unity3d.com/2020.1/Documentation/Manual/UIE-Events-DragAndDrop.html

    Also worth noting that Graph View isn't being developed in place of Graph Tools Foundation. I would be wary about developing too heavily into it.
     
    DanVioletSagmiller likes this.
  3. DanVioletSagmiller

    DanVioletSagmiller

    Joined:
    Aug 26, 2010
    Posts:
    203
    Thank you, that was enlightening: "Graph View isn't being developed" I had been wanting to work with GraphView, and hadn't even realized that there was another Graph thing to look for. I really wish the latest package somehow clarified this. I'm heading over to the new one. Thank you! (Please note, I didn't take your word alone for it, but went to research this first. And everything I saw backed this up, so thank you.)

    No longer looking for an answer for this here.
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,882
    You're a smart man for thinking like this.

    And yeah I was a little bummed to find out the same thing. I'm holding off on Graph tools foundation until it and UI toolkit are better developed... and when I'm also better with in general.