Why is Mass StateTree triggering an assertion "Invalid subchunk"?

I’m following the CitySample example of using the new MassEntity system to create a Mass StateTree with some states and tasks. When I run my level, shortly after I hit this assertion:

Assertion failed: (ChunkIterator->SubchunkStart + ChunkLength) <= Chunk.GetNumInstances() && ChunkLength > 0 [File:D:\UE5\UnrealEngine\Engine\Plugins\Runtime\MassEntity\Source\MassEntity\Private\MassArchetypeData.cpp] [Line: 389]
Invalid subchunk, it is going over the number of instances in the chunk or it is empty.

Has anyone run into this? Any idea what’s going on?

I think I figured this out. In one of my StateTree Task classes (FMassStateTreeTaskBase subclass), in the EnterState method I was calling EntitySubsystem.AddTagToEntity(). I think this was causing the chunk to get modified while it was being iterated over which is bad. To resolve, I had to call EntitySubsystem.Defer().AddTag().

1 Like

Great find. Likewise, I’ll get an editor crash if I am trying to do EntitySubsystem.Defer().{add/remove/tag/fragment} during ExitState. Have you experienced this? Cheers.

No I haven’t tried that scenario. What’s the stack trace and error message?

Dearest Leroyyy231,

I come with a message from the future, approximately 3 days hence from your post.

Regrettably, I do not know the answer to your enquiry. I will entrench myself in the lab, with my faithful assistant Igor and we will, with persistence, divine an answer.