UE5.1 Mass Processor issue

i have learned by epic’s tutorial “Large number of Entities with mass in UE5”,and there is code like


it works in UE5.0 but in UE5.1 the comes error
Assertion failed: ExecutionContext.ExecutionType == ExpectedContextType && (ExpectedContextType == EMassExecutionContextType::Local || bRegistered) [File:D:\build++UE5\Sync\Engine\Plugins\Runtime\MassEntity\Source\MassEntity\Private\MassEntityQuery.cpp] [Line: 154] ExecutionContextType mismatch, make sure all the queries run as part of processor execution are registered with some processor with a FMassEntityQuery::RegisterWithProcessor call

UnrealEditor_MassEntity

UnrealEditor_LMassFramwork_Win64_DebugGame!UTestMovementProcessor::Execute() [E:\UESample\ProTiny\TinyFP\Plugins\LMassFramwork\Source\LMassFramwork\Private\Processor\TestMovementProcessor.cpp:25]

UnrealEditor_MassEntity

You must add the line EntityQuery. RegisterWithProcessor (* this) in the processor configuration of version 5.1

void UXXXXProcessor::ConfigureQueries()
{
	EntityQuery.AddRequirement<FTransformFragment>(EMassFragmentAccess::ReadWrite);

	EntityQuery.RegisterWithProcessor(*this);
}
7 Likes

it realy helps ,thanks a lot

老哥是中国人么,看你主页用的中文

Hi.
In 5.3 this solution don’t work.
Can you help me?

1 Like

The execute function has changed since then

it is now

virtual void Execute(FMassEntityManager& EntityManager, FMassExecutionContext& Context);

Haven’t tested it out but it compiles ok

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "MassProcessor.h"
#include "MassEntitySubsystem.h" 
#include "SimpleRandomMovementProcessor.generated.h"

/**
 * 
 */

UCLASS()
class YOURGAME_API USimpleRandomMovementProcessor : public UMassProcessor
{
	GENERATED_BODY()
public:
	USimpleRandomMovementProcessor();

protected:
	virtual void ConfigureQueries() override;
	//virtual void Execute(UMassEntitySubsystem& EntitySubsystem, FMassExecutionContext& Context) override;

	virtual void Execute(FMassEntityManager& EntityManager, FMassExecutionContext& Context) override;

private:
	FMassEntityQuery EntityQuery;
};

.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "SimpleRandomMovementProcessor.h"
#include "SimpleMovementFragment.h"
#include "MassEntityTemplateRegistry.h"
#include "MassCommonFragments.h"
#include "MassEntitySubsystem.h" 
#include "MassExecutionContext.h"

USimpleRandomMovementProcessor::USimpleRandomMovementProcessor()
{
	bAutoRegisterWithProcessingPhases = true;
	ExecutionFlags = (int32)EProcessorExecutionFlags::All;
	ExecutionOrder.ExecuteBefore.Add(UE::Mass::ProcessorGroupNames::Avoidance);
}

void USimpleRandomMovementProcessor::ConfigureQueries()
{
	EntityQuery.AddRequirement<FTransformFragment>(EMassFragmentAccess::ReadWrite);
	EntityQuery.AddRequirement<FSimpleMovementFragment>(EMassFragmentAccess::ReadWrite);
}

void USimpleRandomMovementProcessor::Execute(FMassEntityManager& EntityManager, FMassExecutionContext& Context)
{

	EntityQuery.ForEachEntityChunk(EntityManager, Context, [this](FMassExecutionContext& Context)
		{
			const TArrayView<FTransformFragment> TransformList = Context.GetMutableFragmentView<FTransformFragment>();
			const TArrayView<FSimpleMovementFragment> SimpleMovementList = Context.GetMutableFragmentView<FSimpleMovementFragment>();
			const float WorldDeltaTime = Context.GetDeltaTimeSeconds();

			for (int32 EntityIndex = 0; EntityIndex < Context.GetNumEntities(); ++EntityIndex)
			{
				FTransform& Transform = TransformList[EntityIndex].GetMutableTransform();
				FVector& MoveTarget = SimpleMovementList[EntityIndex].Target;

				FVector CurrentLocation = Transform.GetLocation();
				FVector TargetVector = MoveTarget - CurrentLocation;

				if (TargetVector.Size() <= 20.f)
				{
					MoveTarget = FVector(FMath::RandRange(-1.f, 1.f) * 1000.f, FMath::RandRange(-1.f, 1.f) * 1000.f, CurrentLocation.Z);
				}
				else
				{
					Transform.SetLocation(CurrentLocation + TargetVector.GetSafeNormal() * 400.F * WorldDeltaTime);
				}
			}
		});

}

Oh and the build file needs the following modules:
MassEntity, MassCommon, MassSpawner

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore",  "MassEntity", "MassCommon", "MassSpawner" });
1 Like

Ok. I already made it.
It would have been great to have had it earlier.

But the problem remains.
When I press start on the editor. The entity spawn but the logic don’t run.

I put a break point inside the Execute() function. It doesn’t run.

Perhaps you need to call:
virtual void Initialize(UObject& Owner) override;
virtual void ConfigureQueries() override;

I would also look into
MassCrowdNavigationProcessor.cpp
to check the internals of initialize and configureQueries
to see what needs to be set for it to run

Solved:
This:

USimpleRandomMovementProcessor::USimpleRandomMovementProcessor()
{
	bAutoRegisterWithProcessingPhases = true;
	ExecutionFlags = (int32)EProcessorExecutionFlags::All;
	ExecutionOrder.ExecuteBefore.Add(UE::Mass::ProcessorGroupNames::Avoidance);
}

Become this:

USimpleRandomMovementProcessor::USimpleRandomMovementProcessor()
	: EntityQuery(*this)
{
	bAutoRegisterWithProcessingPhases = true;
	ExecutionFlags = (int32)EProcessorExecutionFlags::All;
	ExecutionOrder.ExecuteBefore.Add(UE::Mass::ProcessorGroupNames::Avoidance);
}

I copied “UMassLookAtProcessor” .cpp file

3 Likes

Thanks a lot! It really helps!Good guys would enjoy a safe long life.

1 Like