What exactly is a dynamic node?

Forums 💬 NodeCanvas 🗨️ General Discussion What exactly is a dynamic node?

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #14979
    dsedov
    Participant

      I’m trying to grasp this concept, but have hard time fining this concept in the documentation. What exactly is a the use case of a node that is marked as “Dynamic”? I haven’t used one yet, but feel like I’m missing on some important functionality.

      #14989
      grofit
      Participant

        I think it is to do with re-evaluating nodes outside of the normal order, but I like yourself do not really know how to best use them.

        #14988
        Gavalakis
        Keymaster

          The Dynamic setting in either BT node is indeed to revaluate lower priority child nodes for their Status changes.
          Depending on the node type, this might have different effect relative to how they work. So for example:

          What a normal Sequencer does is that it exectus it’s child nodes in order. If one returns Failure, the sequencer stops and returns Failure as well.

          A Dynamic Sequncer will do the same, BUT, lower priority child nodes (those already executed) will be re-valuated. As such if either of them change to Failure, the sequencer will interrup the currently running node and return Failure immediately.

          Take this example:

          Sequencer
          –Condition (if x == true)
          –Action (Wait 3 days)

          A normal sequencer will evaluate the condition once. Lets suppose that x is true, so the sequencer will continue executing the action which will be Running for 3 days. If within that period x becomes false, it wont matter for the sequencer. The action will have to be completed before x is revaluated.

          A Dynamic Sequencer though, even while that super long action is running, if x becomes false at any point, it will iterrupt/stop that super long action and return Failure immediately.

          A more game-ish example:

          Sequencer
          –Condition (HP > 50)
          –Action (Go to $target)

          So with a normal sequencer, here the agent will move to $target if his HP is > 50. If while moving the agent got hit reducing his HP to less than 50, again it won’t matter with the normal sequencer. The agent will move to target no matter what.

          If the Sequencer was Dynamic, as soon as the agent’s HP drop lower than 50, the GoTo action will stop running and the Sequencer will also return Failure.

          I hope that silly example helps 🙂

          #14987
          grofit
          Participant

            That makes it all more clear to me, is there much overhead incurred in dynamics then? as in some of your tree examples on the site you have multi level dynamics, so if you were to have a dynamic above a few sub trees (probably not that likely to happen) but it would need to keep all active nodes on the stack right so it can re-evaulate them?

            #14986
            Gavalakis
            Keymaster

              Glad to hear.

              There is some extra cost with dynamic nodes of course but considering the other ways of doing this around, not really.

              A Dynamic node is dynamic (revaluates) in regards to its child nodes only. Take this example:

              Dynamic Sequencer
              –Condition (x == true)
              –Normal Sequencer
              —-Condition (y == true)
              —-Action1 (Wait 1 day)
              –Action2 (Wait 1 day)

              So, in this setup regardless of which Action of the 2 is running, if x becomes false, action will be interrupted and the root sequencer will return failure. That is because x is checked under the Dynamic Sequencer.
              If though y becomes false nothing will happen immediately, since y is not revaluated “dynamicaly” because that condition is NOT under a Dynamic node.

              You could though mark the 2nd sequencer Dynamic as well, making this whole example tree work dynamic recursively.

              Actions will NOT re-run if they are under a dynamic node due to the node being dynamic. So if you have:
              Dynamic Sequencer
              –Action
              –Action
              –Action

              You wont get 3 actions running and revaluating all the time. You will simply get one as normal.

              So, having a SubTree under a Dynamic Sequencer won’t really make a difference just by itself.

              It needs some experimentation to really grasp them, but believe me, Dynamic Nodes are super useful 🙂
              Let me know if you need more clarification

              #14985
              dsedov
              Participant

                That changes everything! It can make my trees so much smaller now! How is it different from the way Parallel node works, by the way?

                #14984
                dsedov
                Participant

                  I’ve tried something today and it didn’t do what I’ve expected.

                  I have a Dynamic Selector and two subtrees. First subtree is searching if there is a player in sight. Second subtree is making character go between waypoints. It looks like the “search for player” tree is not reevaluated. Inside the “search for player” I have a node that waits until the character reaches the waypoint and that is not getting interrupted.

                  What function does it call on lower priority nodes? OnExecute, or OnUpdate?

                  #14983
                  dsedov
                  Participant

                    These are the screenshots to clarify

                    #14982
                    Gavalakis
                    Keymaster

                      Hey,

                      Marking just that selector as dynamic won’t make a difference. As explained in the previous post, a node is dynamic in respects to it’s child nodes only.
                      Also Actions will not re-execute. Only Conditions will do.

                      So if you mark the root Sequencer in “SearchForPlayer” as dynamic the condition “if ! List is Empty” will revaluate but the actions will not re-execute.

                      The best usage scenario is that you have a condition before some actions that need time to complete and as soon as that condition change, interrupt the actions after it.

                      As for what is called, the OnExecute of the node is called which is responsible to execute the assigned Action or Condition Task.

                      Hope that helps. Let me know if you need more info.

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