Utility Evaluation: Doing something on Exit

Alex

New member
Hello,

I'm testing out the Utility Selector and I was wondering how to tackle a specific problem.
I'm trying a simple "Sims" style utility evaluation where a character has a hunger and boredom value that is used for the evaluation. When the Boredom branch is picked the character goes to a Sofa, sits on it, and then continues to watch tv. Slowly decreasing its boredom value.

Now here is where I'm a bit stuck. When the hunger value becomes larger than the boredom value, the Utility Selector (correctly) switches to the Hunger branch where it will do its own thing. However my character is still sitting on the sofa and needs to "get up" first so to speak. So I need to put a GetUp task somewhere in my tree.

Behavior_Designer.png

Is there a way to make the Evaluate Boredom tree part execute something before being fully aborted by the utility selector? Something equivalent to an OnExitState you would have in an FSM? The only other option I'd see it to have a check at the start of every branch of every branch to see if the character is sitting down on something, but that feels inefficient.

Am I looking at this the wrong way? Or am I missing something here?

Thanks in advance!
 
The only other option I'd see it to have a check at the start of every branch of every branch to see if the character is sitting down on something, but that feels inefficient.
That is the correct solution for right now. I'd like to eventually add a sort of exit branch that gets executed before switching branches (for this and conditional aborts), but I haven't had the chance to implement that yet.
 
That ExitBranch/OnEnd/OnAbort callback functionality would be super useful and I've been trying to figure out a better solution without editing The runtime directly. I have an implementation of an extension to the decorator node that will work but I'll post it when I have tested it a bit more. For now, would the below also as a work around?

1. Extend Action class with a Task called StandUpOnExit.
- in the OnEnd Method, implement the stand up code
- In the OnUpdate, return TaskStatus.Running.

2. In the BT Editor Create a Parallel Task.
- Add an instance of the StandUpOnExit node as a child of the Parallel Task
- move your (Find Couch, Seek, SitOnCouch, WatchTV) as a child of the Parallel Task.

- When the Utility Selector switches branches, the OnEnd of the StandUpOnExit will be triggered and your character will now StandUp.
- This works also with branch failure and conditional abort.
- note StandUpOnExit needs to continue to run by returning TaskStatus.Running.

It's not perfect and a bit verbose but its better than having a bunch of logical checks everywhere.
Would this be robust enough to handle all cases? Thoughts?

Screenshot 2022-04-13 104903.png
 
Last edited:
@Justin Ok, I just wanted to make sure I wasn't overlooking anything obvious. Thanks for the information! I think slipyfrog's idea is also a good choice for simulating an ExitState.

@slipyfrog That's actually an elegant enough solution for what I need. I had not thought of using the parallel composite in that way, good thinking. It'll be a bit more code-y than tree-y that way, but this way at least my "clean up" is in the same branch that it is supposed to clean up. Thanks!
 
Top