Fixing UE5 Chaos Events at Runtime

🔖 game-development ⏲️ 1 minute to read

This is the normal way to receive Chaos events in Unreal Engine 5.1.0, via the editor:

However, if you want to enable these events (OnChaosBreakEvent, OnChaosRemovalEvent, OnChaosCrumblingEvent) programatically without checking them in the editor, you need to do one of the following.

  1. Add at least one UGeometryCollectionComponent in the world which is initialised with bNotifyBreaks, bNotifyCollisions, bNotifyRemovals or bNotifyCrumblings as true (depending on which you are interested in - this is the normal thing if you placed the UGeometryCollectionComponent in the editor and checked the boxes)
  2. Call the Chaos FPhysicsSolver (or FPBDRigidsSolver) with SetGenerateBreakingData, SetGenerateCollisionData, SetGenerateTrailingData or SetGenerateRemovalData

If you don't do one of the above, you do not get any Chaos events if you ask to enable the events after your UGeometryCollectionComponent was already initialised.

If you haven't specified an explicit Chaos solver actor, you are using the "global" solver. To tell that to generate events, you can use the following code (this also shows subscribing to the event generated):

// Need to add the "Chaos" module to Project.Build.cs
#include "PBDRigidsSolver.h"

// Tell the global solver to generate breaking data
Chaos::FPhysicsSolver* Solver = GetWorld()->GetPhysicsScene()->GetSolver();
Solver->EnqueueCommandImmediate([Solver]()
{
	Solver->SetGenerateBreakingData(true);
});

GeometryCollectionComponent->SetNotifyBreaks(true);
GeometryCollectionComponent->OnChaosBreakEvent.AddDynamic(this, &UMyComponent::OnChaosBreak);

Here's where that happens in the UGeometryCollectionComponent, but it's only called when the component is initialised (it doesn't work when you turn on events after the fact): GeometryCollectionComponent.cpp#L1249-L1300

🏷️ chaos editor solver fix ue5 runtime unreal engine world actor code component turn

⬅️ Previous post: Scam Warning

➡️ Next post: Raspberry Pi 4 with Docker

🎲 Random post: Fixing UE5 Actors Disappearing when Building Lighting

Comments

Please click here to load comments.