uPrimitiveComponent->LineTraceComponent in Async Physics Tick

LineTraceComponent used in Async Physics Tick handler complains about:
Ensure condition failed: IsInGameThreadContext() [File:D:\build\++UE5\Sync\Engine\Source\Runtime\Experimental\Chaos\Public\Framework\Threading.h] [Line: 287]

I would like to perform LineTraceComponent during my Async Physics Tick handler in method:
virtual void AsyncPhysicsTickComponent(float DeltaTime, float SimTime) override;

Just before LineTraceComponent I print to log a threadID and name:

uint32 ThreadID = FPlatformTLS::GetCurrentThreadId();
FString ThreadName = FThreadManager::Get().GetThreadName(ThreadID);
UE_LOG(LogTemp, Warning, TEXT("Component->LineTraceComponent on Thread: %u (%s)"), ThreadID, *ThreadName);
bool bhitC = Component->LineTraceComponent(hitC, ps, pe, m_QueryParams);

it results in log output:
LogTemp: Warning: Component->LineTraceComponent on Thread: 22632 (GameThread)

So it looks like called from thread named “GameThread”, so why EnsureIsInGameThreadContext(); fails?

But other thing is why my AsyncPhysicsTickComponent is called from one and always same GameThread (for lot of different components and instances) - shouldn’t it be one of few “Physics threads” that provides this async ticks?

My DefauleEngine.ini part with physics configuration: (my intention is to have 1000Hz physics independent from graphics frames)

[/Script/Engine.PhysicsSettings]
bTickPhysicsAsync=True
AsyncFixedTimeStepSize=0.001000
bSubstepping=False
bSubsteppingAsync=False
MaxSubstepDeltaTime=0.002000
MaxSubsteps=1
MaxAngularVelocity=15000.000000
MaxPhysicsDeltaTime=0.100000
MinPhysicsDeltaTime=0.000100
AnimPhysicsMinDeltaTime=0.001000
SolverOptions=(PositionIterations=16,VelocityIterations=8,ProjectionIterations=2,CollisionMarginFraction=0.050000,CollisionMarginMax=10.000000,CollisionCullDistance=3.000000,CollisionMaxPushOutVelocity=1000.000000,CollisionInitialOverlapDepenetrationVelocity=-1.000000,ClusterConnectionFactor=1.000000,ClusterUnionConnectionType=DelaunayTriangulation,bGenerateCollisionData=False,CollisionFilterSettings=(FilterEnabled=False,MinMass=0.000000,MinSpeed=0.000000,MinImpulse=0.000000),bGenerateBreakData=False,BreakingFilterSettings=(FilterEnabled=False,MinMass=0.000000,MinSpeed=0.000000,MinVolume=0.000000),bGenerateTrailingData=False,TrailingFilterSettings=(FilterEnabled=False,MinMass=0.000000,MinSpeed=0.000000,MinVolume=0.000000))
bDisableCCD=False

full callstack with error message:
callstack.txt (14.5 KB)

Hi,

I went over why these callbacks are executed in the game thread in the other post

Taking that into account, the reason you get the ensure it is because although the code is running on the game thread, it is outside the normal update loop (this is why the code does not check for IsGameThread() only).

Doing scene queries in threads outside the game thread (or the normal update loop) is not supported yet.

Depending on your needs, if you don’t need the results of the query immediately, we have an async scene query API that will still be executed in the game thread, but batched among other queries and run at the end of the frame.

As an example, this is one of the methods available

Hi, thank you for your answer

That what is strange for me is that the World->LineTraceSingleByObjectType (also called from AsyncPhysicsTickComponent) works without triggering this ensure.

As I am able to optimize this line trace by limiting possible objects to few that overlaps my actor, I changed my code to do few quick LineTraceComponent instead of one slow LineTraceSingleByObjectType that runs over whole BVH tree for whole scene.
And generally it works, performance is much better - I do not found any issues so far.
Only this ensure related to thread makes me nervous :slight_smile:

So I am not sure what to do - probably I’ll left it as is, because it works, but I am aware ignoring such warnings means problem “somewhere, sometime”.

For my purpose AsyncLineTraceByChannel doesn’t look good - I need this trace to be performed “ByComponent”, to make use of my short list of possible compoments to trace.