Search Unity

Question Best way of implementing copy and pasting of nodes in graph view?

Discussion in 'UI Toolkit' started by tnyLe, May 20, 2020.

  1. tnyLe

    tnyLe

    Joined:
    Dec 19, 2018
    Posts:
    8
    Hey guys,

    I'm building a dialogue editor for our project and my designer asked if I could implement copy and pasting. We stuck with 2018.3.14f1 and can't afford to risk updating because it might break some other critical plugins. I'm using graph view and because the version is a bit older the graph view api probably is too.

    So I'm wondering if there's a simpler inbuilt way of implementing copy and paste because when you right click in the graph view there's a context menu that appears but with greyed out cut/copy/paste.

    Or do I have to manually implement it myself from scratch?
     
    Last edited: May 27, 2021
  2. PixelLifetime

    PixelLifetime

    Joined:
    Mar 30, 2017
    Posts:
    90
    upload_2020-5-21_14-41-37.png
    I have looked a bit into source code, haven't dug deeper. But I suppose that you should handle copy/pasting yourself via callbacks. It makes sense because as a developer you might want to have control over how your nodes are copied and if they are allowed to be copied at all (some nodes might have restrictions in your graph). You can also look at `ShaderGraph` source code to see how it's done there. I hope with this information you can see what you need to look up into and have an idea where to start.

    Please, let me know if you find a solution to this, as I would like to implement this functionality myself.
     
    tnyLe likes this.
  3. BabyNinja75

    BabyNinja75

    Joined:
    Dec 27, 2018
    Posts:
    1
    I have looked into it and I could handle it like this :
     

    Attached Files:

    gooby429, PixelLifetime and tnyLe like this.
  4. tnyLe

    tnyLe

    Joined:
    Dec 19, 2018
    Posts:
    8
    Yep those are the correct events to listen to.
    I'm still using the same old beta version so the API might be different.
    .serializeGraphElements called when Ctrl+C pressed.
    .unserializeAndPaste and probably .canPasteSerializedData called when Ctrl+V pressed.

    upload_2021-5-27_21-8-29.png

    Cheers guys
     
    PixelLifetime likes this.
  5. Reetro_89

    Reetro_89

    Joined:
    Mar 21, 2021
    Posts:
    4
    Hey sorry to rez a dead thread here but this is the only fourm post I've found that talks about this. My quesetion is how do I go about calculating new node postions? I wanna keep all in the nodes in there same postions when I paste them but just translate X units down or up towards the mouse. Whats the best way implement this?
     
  6. CHE6yp

    CHE6yp

    Joined:
    Mar 4, 2014
    Posts:
    2


    So in this video, Mert (the guy) implements something similar to what you want, starting at around 8:00, he's not copying but creating new nodes, but I'm sure you'll figure it out.
    Video's the third part of the unfinished series, so if his code is too different from yours you might wanna skim through fist two parts.
     
  7. Reetro_89

    Reetro_89

    Joined:
    Mar 21, 2021
    Posts:
    4
    Hey thanks for the response. Looking at that math it would really only work when your pasting only one node. Here is an example with ue4 blueprints of what am trying to achive. Notice how when I paste multiple nodes that they stay in there group and maintain there realative offsets from each other. Example.gif