News Forums Troubleshooting Do Selectors start with first child again every update?

This topic contains 1 reply, has 1 voice, and was last updated by  glennpow 1 day, 5 hours ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #27741


    I’m having trouble getting my logic to flow properly using a BT. I thought I understood how they work, but my observations aren’t matching up with my expectations.

    First, some background of how my BT is constructed:
    In order to simplify the complexity of my BT, I built in the notion of “tasks” (which are essentially ‘states’, but I thought that name conflicted with other elements of the A.I.). A task can be, for example, ‘patrol’, or ‘engage’, or ‘cover’, etc.
    I am using a single large Selector node which then has Condition checks for each of these tasks (task == “patrol”), and then the logic for that task is under that node. The “Task Selector” is directly under the Root node, and is preceded only by the Detect nodes to analyze the environment. The Task Selector is set to repeat Forever, since I want it to always run.

    This system seemed to work fairly well until yesterday when I tried to add one more Condition at the start of the Task Selector. This new Condition checks the variable ‘waitOnAnimation’, which (when set to a string) will cause that animation to play and then wait for it to finish. This is intended to be used as a “pause” in A.I. logic for some reaction animation to take place (such as getting hit or falling down).

    The issue that I’m seeing is that when I set the ‘waitOnAnimation’ variable manually in another script, the Condition check (waitOnAnimation != null) is not evaluating to true until some time later. I believe the cause of this is due to the fact that another task (“patrol”) was still Running at the previous BT update tick, and the WaitOnAnimation Condition had been evaluated to false (since the variable wasn’t set yet).
    Originally, I’d thought that the Task Selector would always run every Condition node under it (from the top) for every BT update tick. But now I’m starting to think that since the “patrol” task was running, then the Task Selector will immediately jump to that node when it starts it’s next BT update. Is that the case?

    Is there any way for me to prevent this? I really want each Condition to be checked every update tick, starting from the top. Would there be a better (more proper) way to handle this logic?

    I can post my BT XML, if necessary, but it’s starting to get quite lengthy.



    Update: I do now strongly believe that Selectors will only restart from the first child when they’ve received a Success response from another child (and the Selector is set to repeat Forever). Is this correct?
    If so, then what is the proper way for the following simple BT to work, so that when the “itr” memory variable reaches 100, it will break the patrol branch, and allow the first Condition to execute? This would cause it to pause for a few seconds and then restart “itr” to zero. (Assume that the patrol branch always returns Running, since the character will keep walking to waypoints forever).

    <behaviortree version="1.1" repeatuntil="" name="Selector Test">
      <parallel tiebreaker="fail" succeed="all" repeatuntil="" name="root" fail="any">
        <expression returnvalue="success" repeatuntil="running" name="expression" expression="itr += 1" />
        <selector usepriorities="False" repeatuntil="running" name="check task">
          <constraint repeatuntil="" priority="" name="animate" constraint="itr >= 100">
            <timer waitforsec="3" returnvalue="success" name="timer" />
            <expression returnvalue="success" repeatuntil="" name="expression" expression="itr = 0" />
          <constraint repeatuntil="" priority="" name="patrol" constraint="true">
            <parallel tiebreaker="fail" succeed="any" repeatuntil="" name="patrol" fail="any">
              <waypointpatrol waypointsetvariable=""Waypoint Route"" waypointactiontype="patrol" traversetype="loop" traverseorder="forward" repeatuntil="" pathtargetvariable="" name="waypointpatrol" movetargetvariable="moveTarget">
                <move turnspeed="" repeatuntil="" name="move" movetarget="moveTarget" movespeed="" facetarget="" closeenoughdistance="" closeenoughangle="" />
              <animate repeatuntil="running" name="animate patrol" animationstate="Walk" />
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.