State Tree Transitions

Sup everyone, I’m really new to state trees and I need some advice and help with an issue I’m having with my AI enemy, I’m trying to create a weak state where if its health reaches a certain point it will stop chasing the player, and after 10 secs it will continue with the rest of the tree, I must add that every print string you see inside the code prints perfectly, but inside the boss weak custom event the two print strings print at the same time so the delay aint working, hopefully i get some help. Thank you.

Use sub-states under weak sequentially:
Weak
–CheckWeakStatsState
**STT_Weak

–DelayState
**Delay

–ChaseState
**STT_Chase

What is happening is the FinishTask is executing in STT_Weak (and prob STT_Chase) and stepping to the next state immediately. You still have the delay happening, it just doesn’t do anything but spin clock cycles as all your tasks are executing in your weak state at the same time.

FinishTask and state/task execution order can be a bit confusing at first… it still gets me every once in a while.

Also, definitely use the Debugger in addition to your print strings. It’s vital for watching your states during gameplay, it highlights exactly what’s going on in the state tree while the game is running in PIE and points out issues with transitions immediately.

I’m gonna have to do more research on State Trees, but I did get it to work by moving the delay to the task and then added a Boolean weak check inside the boss blueprint.

quick question is it better to do logics inside the character blueprint or inside the tasks?

I prefer to put my logic into the tasks, only utility functions that I build to re-use end up in the actor/pawn blueprint. Generally I start like you have, then eventually migrate what makes sense to a task to keep state logic in the state tree. This can keep your pawn BPs really clean and modular.

A couple other things:
*Make sure you set up your state tree context properly.
*For ease and reuse, I create parent tasks like STT_NPCTask_Base and do setup there along with some other convenience functions, then inherit from them for the built tasks… just make sure you call the parent functions in your overrides.

I see. I was thinking about that reuse stuff, so I could easily use it on more than one NPC instead of recreating stuff.

Do you have any video recommends or documentations I could follow? as of right now state trees seems more easier to start with than behavior trees.

Yeah the reuse is very powerful. Also consider you can use statetreecomponent almost anywhere, not just npcs. For instance, I use them to control gameplay state and flow for the entire game. I use a custom actor for this but you could add the statetree component to your own derived GameMode or GameState for the same effect. The time based debugger is awesome for scrubbing back and seeing what happened during gameplay.

For vids, nothing out there that helped more than playing around with it. The unreal docs are ok:

This is useful, I think:

I used behavior trees for quite a while but they are limited and a pain to debug for complex trees. I don’t think epic is really putting anything more into them besides bug updates. State trees are updated and more ‘future proof’ if you’re going to learn something.