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.

Interrupting execution in a custom node

Discussion in 'Visual Scripting' started by ChaosCraft, Aug 7, 2022.

  1. ChaosCraft

    ChaosCraft

    Joined:
    Feb 8, 2022
    Posts:
    7
    I am wanting to understand how to write a custom node that will pause the graph execution and wait for a set of external events before it resumes. (if this is all documented somewhere I'm happy to work it out from that, but I can't find that level of doco so far)
    I am aware (or at least have the impression) I can do this using a sub-graph, but I want to do it entirely in the node (the goal is to make this easier for our writers to assemble graphs - a sub-graph will just confuse)
    BTW, this is not an action game - this pause can be effectively a full game pause while the task is completed - though better if everything else can keep running.
    To make the example specific...
    I want to create a nodeType GetTargetSelection. It will take an input list of possible targets, and output a list of the targets the user has selected, or an empty list. It also will choose the controlOutput flow based on the user selections.
    To do this it will take the input list and tell each possible target to highlight itself.
    It will display a dialog (or other system) offering cancel and complete buttons, showing the number of targets selected and showing the max/min selections required
    It will then hand control back to the player who can now click on individual targets to select/deselect them.
    As the player does this, cards will throw clicked events (or selected/deselected events) that the node will want to capture.
    As the node captures the events it will maintain an internal selection list and update the dialog.
    When the player selects cancel an empty list will be set on the output, and the canceled controlFlow will be triggered.
    When the player selects complete (only available when the count is in range) the selection list will be passed on and the completed controlFlow will be triggered.
    As I say, I can see how I might do this as a sub-graph, but that will be far less useful than a stand-alone node for this.
    From the writer's perspective, they can just say "here is the list of possible targets. Now I want the player to select 1-3 of them"
    Can anyone help me understand how I write that into a C# custom node script? I'm sure it will involve some cleverness around the flow object, but I can't find any documentation on the topic.

    As a last question, if this really can't sensibly be done in a custom node, is there a way to define new node-types that are based on sub-graphs, so the writer can just drag the whole behavior into the graph where needed?

    I hope someone can help me with this - the graph system looks awesome if I can just get my head around it.

    Regards,
    Keith Ealanta (Chaos Crafter)
     
  2. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    355
    Well in UVS you would use Wait While [condition]/[AND conditions]. If you wanted to incorporate directly into your own custom node, have a look at the Wait units code that is what I'd do (if you want complex), but mainly it might be easier to make a custom node that outputs a condition based on custom input say, avoiding the coroutine part. You may want a manager/controller that pauses until conditions are met, while another graph is the loop function doing something per frame. I personally would use as little graphs as possible, just a logical controller and loop, multi-leveled with parallel state machines since state machine are also another way of waiting for conditions to be met.