News › Forums › RAIN › General Discussion and Troubleshooting › What to drag into the Behavior Editor to get AI to call a function ?
Tagged: Custom Action
This topic contains 3 replies, has 2 voices, and was last updated by Sigil 1 month, 1 week ago.
December 10, 2022 at 5:17 am #39657
What to drag into the Behavior Editor to get AI to call a function when Move target variable change ?
My behavior tree is as easy as it gets for now.
Screenshot incase cropped.
http://s21.postimg.org/sur4vtf6d/image.pngDecember 10, 2022 at 11:09 am #39666
You could add a custom action after the move node, which would get called every time the AI reached a waypoint in its route. The custom action is in the right click menu under actions, once you add it you can tell it to create a new custom action (the code part of it). It’ll ask you the scripting language, name, and will generate a file for you.
There are some examples of other custom actions around here that might give you some insight.December 10, 2022 at 11:51 am #39667
Thank you Sigil for trying to help.
I couldn’t get ai.WorkingMemory.GetItem to work.
But even before that, is my behavior tree even correct ?
Should I but the Mecanim parameter setter right below parallel ?
or should I put it below the wayward point patrol next to move ?
How many time is that called anyway ? The move action I mean…does it get called once and it executes the move ? or it is called 60 times per second sort of like an update ? I don’t understand this behavior tree execution cycle at all.
Why is it that if I put “random” right below “BT” whatever “BT” means and then split it into wayward patrol and some other brunch it doesn’t random at all ?
what is the difference between Selector and Sequence ?
The documentation is really badDecember 14, 2022 at 10:56 am #39736
Sorry for the late reply.
Let’s start with the way a behavior tree updates. So the behavior tree gets executed every frame, just like the MonoBehaviour Update function. So the Basic Mind always starts execution at the root node of the behavior tree, and essentially asks the node if it succeeded, failed, or is still running. The root node usually has a child, so it asks the child whether is succeeded, failed, or is still running, and this continues on down the tree until we get to a node like a custom action, timer, mecparam, move, etc.
So for a simple example, just a move node, each frame the tree asks the move node what its result was. If the move node hasn’t reached its target yet, it attempts to move towards the target (just a little bit, using its velocity and Time.deltaTime), and then returns running. The next frame, the tree remembers that the move node returned running so it goes right back to the move node, skipping everything else. This continues until the move node reaches its target, at which point the move node returns success.
So the entire tree works this way, each node running their task and returning success, failure, or running. If at any point a node returns running, the tree remembers this and returns to that node on the next frame. As long as the node continues to return running the tree will continue going back to it, ignoring the rest of the tree. This allows you to run longer tasks (like moving) over several frames.
The selector node runs its children in order until one of them returns success. It is usually used to select between several tasks: do A, or if A fails do B, or if B fails do C, etc. A sequencer runs its children in order until one of them returns failure. So unlike a selector, it attempts to run every single child in sequence: do A, and if A succeeds do B, and if B succeeds do C, etc.
BT stands for behavior tree, and its just there to represent the root of the tree. The first child of the BT node will be the one that is executed.
Likely the reason your random didn’t do what you thought it would is because it got stuck on a running task. It picks a random branch to run, and will continue to run that branch until it returns success or failure. So in your example, if your waypoint patrol node was chosen, it would return running until the AI finishes patrolling, keeping the random node from choosing another node until then.
You must be logged in to reply to this topic.