Fixing UE5 Chaos Events at Runtime
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.
- Add at least one
UGeometryCollectionComponent
in the world which is initialised withbNotifyBreaks
,bNotifyCollisions
,bNotifyRemovals
orbNotifyCrumblings
as true (depending on which you are interested in - this is the normal thing if you placed theUGeometryCollectionComponent
in the editor and checked the boxes) - Call the Chaos
FPhysicsSolver
(orFPBDRigidsSolver
) withSetGenerateBreakingData
,SetGenerateCollisionData
,SetGenerateTrailingData
orSetGenerateRemovalData
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
Please click here to load comments.