# Async physics creation locks the main thread 

**URL:** <https://forums.unrealengine.com/t/async-physics-creation-locks-the-main-thread/2690493>\
**Category:** Platform & Builds\
**Tags:** unreal-engine, Epic-Pro-Support, question\
**Created:** [September 24, 2025, 1:17am UTC](https://forums.unrealengine.com/t/async-physics-creation-locks-the-main-thread/2690493 "2025-09-24T01:17:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous-edc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous-edc](https://forums.unrealengine.com/u/anonymous-edc)\
**Post date:** [September 24, 2025, 1:17am UTC](https://forums.unrealengine.com/t/async-physics-creation-locks-the-main-thread/2690493/1 "2025-09-24T01:17:36Z")

</div>

With the implementation of asynchronous body creation, its possible to fairly regularly lock the main thread -- essentially defeating the purpose of all this work.

Here we have 63ms of async physicsbody creation happening on a background task. The problem is that there’s a fairly non-granular lock applied here so if the main thread attempts to do anything with the chaos it simply stalls:

[Image Removed]

And here our mainthread takes almost 60ms as opposed ti its normal ~16ms because every physics related call is inflated by locks

[Image Removed]

This seems to specifically be the problem. [Image Removed]

I’m playing around with a local change, basic idea is to break the list into chunks in AddActorsToScene\_AssumesLocked. Lock chaos, take x number of actors, process them, release the lock and yield so that other threads can process if necessary.

Thanks,

Brenden

---

<div class="post-metadata">

**Author:** ![anonymous-edc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous-edc](https://forums.unrealengine.com/u/anonymous-edc)\
**Post date:** [September 26, 2025, 1:36pm UTC](https://forums.unrealengine.com/t/async-physics-creation-locks-the-main-thread/2690493/2 "2025-09-26T13:36:18Z")

</div>

```auto
void FChaosScene::AddActorsToScene_AssumesLocked(TArray<FPhysicsActorHandle>& InHandles, const bool bImmediate /*= true*/)
{
	TRACE_CPUPROFILER_EVENT_SCOPE(FChaosScene::AddActorsToScene_AssumesLocked);
 
	Chaos::FPhysicsSolver* Solver = GetSolver();
	Chaos::ISpatialAcceleration<Chaos::FAccelerationStructureHandle, Chaos::FReal, 3>* SpatialAcceleration = GetSpacialAcceleration();
 
	const int32 BatchSize = (GChaos_AddActorsBatchSize > 0) ? GChaos_AddActorsBatchSize : InHandles.Num();
 
	for (int32 Start = 0; Start < InHandles.Num(); Start += BatchSize)
	{
		const int32 End = FMath::Min(Start + BatchSize, InHandles.Num());
 
		{
			UE_CHAOS_ASYNC_INITBODY_PHYSICSSCENE_WRITESCOPELOCK(Solver->GetExternalDataLock_External());
 
			for (int32 Index = Start; Index < End; ++Index)
			{
				FPhysicsActorHandle& Handle = InHandles[Index];
				FChaosEngineInterface::AddActorToSolver(Handle, Solver);
 
				if (bImmediate && SpatialAcceleration)
				{
					const Chaos::FRigidBodyHandle_External& Body_External = Handle->GetGameThreadAPI();
					const bool bHasBounds = Body_External.GetGeometry()->HasBoundingBox();
 
					Chaos::FAABB3 WorldBounds;
					if (bHasBounds)
					{
						const Chaos::FAABB3 LocalBounds = Body_External.GetGeometry()->BoundingBox();
						WorldBounds = LocalBounds.TransformedAABB(Chaos::FRigidTransform3(Body_External.X(), Body_External.R()));
					}
 
					Chaos::FAccelerationStructureHandle AccelHandle(Handle->GetParticle_LowLevel());
					SpatialAcceleration->UpdateElementIn(AccelHandle, WorldBounds, bHasBounds, Body_External.SpatialIdx());
				}
			}
		}
 
		// Allow other threads a chance at the lock between batches.
		FPlatformProcess::YieldThread();
	}
}

```

After quite a bit of testing. This proved to be very successful. Instead of locking for the entire addition, we break it into batches and yield to other threads in between iterations. Main thread runs buttery smooth now.

---

<div class="post-metadata">

**Author:** ![geoffstacey\_work](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@geoffstacey\_work](https://forums.unrealengine.com/u/geoffstacey_work)\
**Post date:** [October 2, 2025, 7:34am UTC](https://forums.unrealengine.com/t/async-physics-creation-locks-the-main-thread/2690493/3 "2025-10-02T07:34:00Z")

</div>

Hi Brenden,

Could you attach the trace file for this please? I’d like to take a look through it

Geoff Stacey

Developer Relations

EPIC Games

---

<div class="post-metadata">

**Author:** ![geoffstacey\_work](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@geoffstacey\_work](https://forums.unrealengine.com/u/geoffstacey_work)\
**Post date:** [December 9, 2025, 9:19am UTC](https://forums.unrealengine.com/t/async-physics-creation-locks-the-main-thread/2690493/4 "2025-12-09T09:19:46Z")

</div>

Thanks Brenden,

One of my colleagues has also just published an article which may help (depending on how large each ISM component actually is).

> **[Level Streaming Hitching Guide | Tutorial](https://dev.epicgames.com/community/learning/tutorials/qpll/unreal%5C-engine%5C-level%5C-streaming%5C-hitching%5C-guide)**
>
> Guide to recognizing common level streaming hitches in your Unreal Insights captures and tips and links to resources to address them. Hitches refers to ...

Best

Geoff

---

<div class="post-metadata">

**Author:** ![anonymous-edc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous-edc](https://forums.unrealengine.com/u/anonymous-edc)\
**Post date:** [October 2, 2025, 1:55pm UTC](https://forums.unrealengine.com/t/async-physics-creation-locks-the-main-thread/2690493/5 "2025-10-02T13:55:00Z")

</div>

Unfortunately the traces have been cleared since we made the above change and at this stage the issue is resolved so it doesn’t really show up on new traces.
