UE 5.6 Crash when opening scene containing Actors with MassAgentComponent

I just upgraded to 5.6 today and I’m experiencing a crash when opening scenes that contains Actors with MassAgentComponent.

As soon as scene opens the engine crashes with this callstack:

|>|[Inline Frame] UnrealEditor-MassEntity.dll!TMapBase<UScriptStruct const *,int,FDefaultSetAllocator,TDefaultMapHashableKeyFuncs<UScriptStruct const *,int,0>>::FindChecked(const UScriptStruct *) Line 729|C++|
|---|---|---|
| |UnrealEditor-MassEntity.dll!FMassArchetypeData::SetFragmentData(TArrayView<FMassArchetypeEntityCollection::FArchetypeEntityRange const ,int> EntityRangeContainer, const FInstancedStruct & FragmentSource) Line 447|C++|
| |UnrealEditor-MassEntity.dll!FMassEntityManager::BatchSetEntityFragmentValues(TArrayView<FMassArchetypeEntityCollection const ,int> EntityCollections, TArrayView<FInstancedStruct const ,int> FragmentInstanceList) Line 1780|C++|
| |UnrealEditor-MassSpawner.dll!UMassSpawnerSubsystem::DoSpawning(const FMassEntityTemplate & EntityTemplate, const int NumToSpawn, FConstStructView SpawnData, TSubclassOf<UMassProcessor> InitializerClass, TArray<FMassEntityHandle,TSizedDefaultAllocator<32>> & OutEntities) Line 139|C++|
| |UnrealEditor-MassSpawner.dll!UMassSpawnerSubsystem::SpawnEntities(const FMassEntityTemplate & EntityTemplate, const unsigned int NumberToSpawn, TArray<FMassEntityHandle,TSizedDefaultAllocator<32>> & OutEntities) Line 63|C++|
| |UnrealEditor-MassActors.dll!UMassAgentSubsystem::HandlePendingInitialization() Line 328|C++|

Same happens with a dev build with the same callstack

FDebug::CheckVerifyFailedImpl2()
FMassArchetypeData::SetFragmentData()
!FMassEntityManager::BatchSetEntityFragmentValues()
UMassSpawnerSubsystem::DoSpawning()
UMassSpawnerSubsystem::SpawnEntities()
UMassAgentSubsystem::HandlePendingInitialization()
TBaseUObjectMethodDelegateInstance<0,UMassAgentSubsystem,void __cdecl(float),FDefaultDelegateUserPolicy,enum EMassProcessingPhase>::ExecuteIfSafe()
IslesOfKrom!TMulticastDelegate<void __cdecl(float),FDefaultDelegateUserPolicy>::Broadcast()

From what I understand there seems to be discrepancy between the archetype and the data passed since it crashes when trying to find an absent fragment in the archetype.

I have no idea how I can fix this issue and I would gladly welcome some help in order to fix this issue.

Thanks in advance.

1 Like

I manage to reproduce the issue in an empty project. Using only 2 actors that have each one specific traits. The traits are very simple and look like the code below:
Simply having one bp with a massAgentComponent and an EC config sporting the first trait and a second Bp with also a massAgentComponent and a second EC Config sporting the secont trait is enough to crash the engine when the scene opens.

USTRUCT()
struct FFragment1 : public FMassFragment
{
	GENERATED_BODY()

	UPROPERTY()
	int32 Counter;
};

USTRUCT()
struct FFragment2 : public FMassFragment
{
	GENERATED_BODY()

	UPROPERTY()
	int32 Counter;

	UPROPERTY()
	FName Name;
};

USTRUCT()
struct FFragment3 : public FMassFragment
{
	GENERATED_BODY()

	UPROPERTY()
	int32 Counter;

	UPROPERTY()
	float Perc;
};

USTRUCT()
struct FTag1 : public FMassTag
{
	GENERATED_BODY()
};

UCLASS()
class MYPROJECT2_API UTraits1 : public UMassEntityTraitBase
{
	GENERATED_BODY()

public:

	virtual void BuildTemplate(FMassEntityTemplateBuildContext& BuildContext, const UWorld& World) const override;
};

UCLASS()
class MYPROJECT2_API UTraits2 : public UMassEntityTraitBase
{
	GENERATED_BODY()

public:

	virtual void BuildTemplate(FMassEntityTemplateBuildContext& BuildContext, const UWorld& World) const override;
};

void UTraits1::BuildTemplate(FMassEntityTemplateBuildContext& BuildContext, const UWorld& World) const
{
	FFragment1 Fragment1;
	Fragment1.Counter = 0;
	BuildContext.AddFragment(FConstStructView::Make(Fragment1));

	FFragment2 Fragment2;
	Fragment2.Counter = 0;
	Fragment2.Name = FName{TEXT("Traits1")};
	BuildContext.AddFragment(FConstStructView::Make(Fragment2));
}

void UTraits2::BuildTemplate(FMassEntityTemplateBuildContext& BuildContext, const UWorld& World) const
{
	BuildContext.RequireFragment<FMassActorFragment>();
	BuildContext.AddTag<FTag1>();

	FFragment2 Fragment3;
	BuildContext.AddFragment(FConstStructView::Make(Fragment3));
}