If the static mesh has UseSimpleCollisionAsComplex and does not have any SimpleCollision shapes, The physics actor will be destroyed immediately in FInitBodiesHelperBase::CreateShapesAndActors, but since it is before the scene is added, the PhysicsActor will be delayed until the persistent level is destroyed.

This can be fatal for titles which use switching sublevels repeatedly without changing persistent level.


Here's a fix

// Takes actor ref arrays.
// #PHYS2 this used to return arrays of low-level physics bodies, which would be added to scene in InitBodies. Should it still do that, rather then later iterate over BodyInstances to get phys actor refs?
bool FInitBodiesHelperBase::CreateShapesAndActors()
		CreateActor_AssumesLocked(Instance, Transform);
		const bool bInitFail = CreateShapes_AssumesLocked(Instance);
		if (bInitFail)
			//In the editor we may have ended up here because of world trace ignoring our EnableCollision. Since we can't get at the data in that function we check for it here
			if(!PrimitiveComp || PrimitiveComp->IsCollisionEnabled())
				UE_LOG(LogPhysics, Log, TEXT("Init Instance %d of Primitive Component %s failed. Does it have collision data available?"), BodyIdx, *PrimitiveComp->GetReadableName());
#if 0
			FPhysicsInterface::ReleaseActor(Instance->ActorHandle, PhysScene );
#else  // this is the workaround
			FPhysicsInterface::ReleaseActor(Instance->ActorHandle, PhysScene, true/*bNeverDeferRelease*/ ); 
			Instance->OwnerComponent = nullptr;
			Instance->BodySetup = nullptr;
			Instance->ExternalCollisionProfileBodySetup = nullptr;
		FPhysicsInterface::SetActorUserData_AssumesLocked(Instance->ActorHandle, &Instance->PhysicsUserData);
	return true;





Steps to Reproduce
  1. Compile and open attached project [Link Removed]on 4.25 or 4.26
  2. Add "-llm" command option in Play > Advanced option > Additional launch parameters
  3. Launch standalone game
  4. After launching application, enter "stat llm"
  5. Press 1 key repeatedly to toggle a sublevel
  6. Observe the PhysX memory rows in the LLM stats


Each time displaying the sublevel increase PhysX memory by around 10 KBytes.

[Link Removed]

Have Comments or More Details?

There's no existing public thread on this issue, so head over to AnswerHub just mention UE-113811 in the post.

Login to Vote

ComponentSimulation - Physics
Affects Versions4.25
Target Fix4.27
CreatedApr 19, 2021
UpdatedApr 27, 2021