News › Forums › RAIN › General Discussion and Troubleshooting › Pause execution of behavior tree
This topic contains 8 replies, has 2 voices, and was last updated by prime 2 months, 2 weeks ago.
-
AuthorPosts
-
December 16, 2022 at 9:16 am #34791
I have a model with a behavior tree attached to it that’s a basic waypointpatrol. I need for the model to not begin that behavior tree until a certain event occurs. How would I go about stopping this behavior tree from executing on start up, and then starting it when my particular event occurs?
December 16, 2022 at 9:19 am #34792A simple approach would be to do this:
SELECTOR:
— EVALUATE EXPRESSION (event hasn’t happened)
— SEQUENCER
— — EVERYTHING ELSEDecember 16, 2022 at 9:24 am #34793I’m not sure I can specify this particular event within the behavior tree. It’s an augmented reality shooter game and I need it to wait until I have the tracking image in view before starting the behavior tree. So I have a C# file that’s overriding a method that checks if a tracking image has been seen by the camera. This is where I would need to place some logic to start up the behavior tree, if that’s possible.
December 16, 2022 at 11:08 am #34794Other options then:
1) Just set your AI to inactive until it is ready to go.
AIRig tRig = gameObject.GetComponentInChildren<AIRig>(); tRig.AI.IsActive = true;
2) Stick with the Selector, but use your script to indicate whether you are ready to go.
AIRig tRig = gameObject.GetComponentInChildren<AIRig>(); tRig.AI.WorkingMemory.SetItem<bool>("ready", true);
3) Activate/Deactivate the entire character game object using Unity methods.
December 16, 2022 at 2:14 pm #34797Thanks for the reply. With option #1 using my own script I’m getting the error: “Cannot implicitly convert type ‘RAIN.Core.AIRig[]’ to ‘RAIN.Core.AIRig'” on this line:
AIRig tRig = gameObject.GetComponentInChildren<AIRig>();
So I need to store the return from gameObject.GetComponentInChildren<AIRig>() in an array then?
December 16, 2022 at 2:18 pm #34799Did you accidentally use GetComponentsInChildren?
December 16, 2022 at 2:20 pm #34800Good call, didn’t notice that.
December 16, 2022 at 2:37 pm #34801Should I then be setting the AI inactive in the Start() method and then can I set it back to active in the Update() method once a condition is reached? So far I can get it inactive with this method, but no luck in turning it back on.
December 17, 2022 at 7:43 am #34808Yes, you should be able to simply toggle IsActive true or false to get what you want. IsActive shouldn’t impact initialization of the AI, just the running behavior.
-
AuthorPosts
You must be logged in to reply to this topic.