Hi,
I’ve just started to play around with StateTrees and got stuck now. I created a very simple random wait task which should wait between 3 and 7 seconds and then repeat, but somehow the task is only ticking once after start and thus never finishes. When I stop playing it executes the ExitState and thats it.
Hey @Razdraz
My best guess is that is has to do with your Random Wait Task. You probably just need to override your exit state and make something to finish to the tree.
As I said, the ExitState gets called when I stop playing. The problem is that the Tick function is just called once after start.
In the enter state I return EStateTreeRunStatus::Running and in the Tick function I decrease the timer and return EStateTreeRunStatus::Succeeded when timer reaches <=0, otherwise I return EStateTreeRunStatus::Running.
I just don’t know why it isn’t ticking anymore after start.
Okay I somewhat figured out that it needs MassSignals to work, but I still don’t get it. I think I need to wait till more documentation is available on this topic.
When I send a signal within the Tick function to the entity it keeps ticking, but I cannot imagine that this is the right way. I also cannot find any signals within the tick funtion of the already builtin tasks (FMassLookAtTask.cpp for instance)
The Tick function on state tree tasks is misleading. It will only get called when someone calls UMassSignalSubsystem SignalEntity or DelaySignalEntity as you alluded to. The idea is that in EnterState you configure entities such that a processor will do the work for that task, and then once that task is done, it should use UMassSignalSubsystem to trigger the Tick function, where you then can mark the task done. You don’t have to use a processor to mark the task complete, you can do it in the task itself. For example take a look at how in FMassLookAtTask::EnterState they call MassSignalSubsystem.DelaySignalEntity which will trigger the Tick function to be called and complete the task.
I thought that this function would be called every frame or with a certain frequency. I think it should be renamed somehow, giving it a clearer name that reflects its essence.
The concept of using StateTree with Mass is to have tasks that add or modify fragments that are then executed on by Mass processors. This is done because UMassStateTreeProcessor requires the game thread to be run, and ticking all StateTrees on the game thread would be quite expensive (30k pedestrians in CitySample all running a StateTree). The method certainly has a misleading name, but it does tick when used in the Actor context of the engine.
The Mass StateTree should only ever “Tick” when it needs to re-evaluate a possible transition. This is done in how the MoveTo tasks and processors work. You can set up your own signals to use if you want a periodic tick of the StateTree, but this would not be recommended. Instead, we advise moving logic out of the Tick on the task and into a processor’s Execute method.