NodeCanvas Forums › General Discussion › BT and sub FSMs question
Hi,
this question is kind of related to this: .
Right now my set up for the enemy AI is BT -> sub-FSM and the states of the FSM are BTs. I do this because I need to do some checks all the time, no matter what state the FSM is in. For example target visibility checks or fight engagement checks.
What do you think about that? I wouldn’t want to have the same checks in all of the FSM states and it doesn’t really work with a concurrent state in the FSM. Any suggestions?
This question is kind of related to a best practices approach for how to solve problems using NodeCanvas.
It would be great to sometime see a bit more complicated (more “real game”) AI example.
Cheers,
Felix
p.s.: at least the email notification for follow ups on this forum doesn’t work – checked the spam folder as well – nothing
Hello,
Generally speaking, I would probably never use a Behaviour Tree with SubFSMs as at least to me, it makes much more sense that the “root”, is an FSM (with BT States) rather than a BT (with nested FSMs). This way, the login is more clearly separated into states and each state (a BT) defines the logic of that state, while the transitions when to change the states.
I would use a BT as “root” only with SubBTs and not SubFSMs.
To be honest, some time ago I was considering deprecating Nested FSM in BTs completely just to provide a more streamlined workflow, but some people were still using them, so this never happened 🙂
As far as doing checks regardless of what state the FSM is in, would not the “Any State” work for what you are after?
Please let me know what you think.
(PS: Hmm. I will check the follow up email notification. Never reported that it does not work before.)
Join us on Discord: https://discord.gg/97q2Rjh
Hi,
first of all thanks for your quick answer(s), as always :).
What I’m trying to do is have several checks going on at the same time while the FSM with the “main character logic” with nested BTs is running. I need to check if the character is engaged in a fight (how close, line of sight, inside sensor etc) or set some variables if sensors are entered/exited. Since I want these checks to run all the time and don’t want to copy paste them to different states (meaning different BTs) I somehow can’t see how I could achieve that with the anystate, since then I’d have to add more states just for setting variables (?).
I hope you understand what I mean.
Hello,
Yes, using AnyState here would indeed mean adding extra intermediate states that would set the variables you need when something happened, then transition to the required SubBT, which in turn will simply make use of these variables that have now been set.
One other alternative, would be to have one (or more) concurrent nodes in the FSM set on repeat, and with custom actions that will continuously be evaluating the check your require and setting variables accordingly. As such, irrelevantly of which state (or BT State) the FSM is currently at, the variables will be set in parallel and ready to be used from all states. This if probably a better solution.
Let me know if that works for you and your thoughts.
Cheers!
Join us on Discord: https://discord.gg/97q2Rjh
Hi,
thinking about these solutions in my opinion still a top level bt is somehow more straightforward and less “hacky” – alternatively I’m thinking about just directly coding the desired checks in my character scripts and setting the according variables in the blackboard from there.
Still always good to think about different alternatives.
Cheers,
Felix
Hey,
There are certainly many ways to approach this and no solution is definite of course 🙂
Another approach that you might want to consider (based on your last post), is to Bind certain blackboard variables to properties on some custom script attached on the gameobject and have those properties do the checks your require. This way, you are able to use these property bound variables (and thus checks) from wherever in your graph hierarchy and they will always evaluate only when you “get” them.
So, for example you could have a bool variable “isEngaged” bound to a bool property of one of your custom scripts and in return that property will perform the check and return true/false accordingly when requested.
🙂
Join us on Discord: https://discord.gg/97q2Rjh
In this case I need to do the checks (at least almost) every frame anyway.
Thankfully NC is flexible enough to allow for many possibilities to solve problems.
Thanks!