StateTree task only ticking once

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.

Any suggestions appreciated :slight_smile:

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.

I hope this can help!
-Zen

Hi, thanks for your reply.

I override all necessary functions (c++), it looks like this:

USTRUCT(meta = (DisplayName = "Random Wait Task"))
struct PROJ_API FTestWaitTask : public FMassStateTreeTaskBase
{
	GENERATED_BODY()

	using FInstanceDataType = FMassTestWaitTaskInstanceData;

protected:
	virtual bool Link(FStateTreeLinker& Linker) override;
	virtual const UStruct* GetInstanceDataType() const override { return FInstanceDataType::StaticStruct(); }
	virtual EStateTreeRunStatus EnterState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition) const override;
	virtual void ExitState(FStateTreeExecutionContext& Context, const FStateTreeTransitionResult& Transition) const override;
	virtual EStateTreeRunStatus Tick(FStateTreeExecutionContext& Context, const float DeltaTime) const override;
};

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.