lucakd
(lucakd)
April 17, 2023, 1:21pm
1
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
zyquan
(zyquan)
April 17, 2023, 11:00pm
2
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
lucakd
(lucakd)
April 18, 2023, 3:05am
3
it realy helps ,thanks a lot
oWASDo
(oWASDo)
November 12, 2023, 8:29pm
5
Hi.
In 5.3 this solution don’t work.
Can you help me?
1 Like
3dRaven
(3dRaven)
November 12, 2023, 9:36pm
6
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
oWASDo
(oWASDo)
November 13, 2023, 9:00am
7
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.
3dRaven
(3dRaven)
November 13, 2023, 10:48am
8
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
oWASDo
(oWASDo)
November 13, 2023, 3:35pm
9
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
ZLYEYE
(Zhilin)
July 19, 2024, 4:03am
10
oWASDo:
: EntityQuery(*this)
Thanks a lot! It really helps!Good guys would enjoy a safe long life.
1 Like