UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ChaosGameplayEventDispatcher.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "PhysicsPublic.h"
9#include "ChaosGameplayEventDispatcher.generated.h"
10
11struct FBodyInstance;
12
13namespace Chaos
14{
15 struct FCollisionEventData;
16 struct FBreakingEventData;
17 struct FSleepingEventData;
18 struct FRemovalEventData;
19 struct FCrumblingEventData;
20 struct FBreakingData;
21}
22
24
26USTRUCT()
34
36
38USTRUCT()
46
48
50USTRUCT()
58
60USTRUCT()
62{
64
65 bool bLegacyComponentNotify;
66
68 UPROPERTY()
69 TSet<TObjectPtr<UObject>> ChaosHandlers;
70};
71
77
78
79UCLASS(MinimalAPI)
81{
83
84public:
85
87
88 CHAOSSOLVERENGINE_API virtual void OnRegister() override;
89 CHAOSSOLVERENGINE_API virtual void OnUnregister() override;
90
91 CHAOSSOLVERENGINE_API void RegisterChaosEvents();
92 CHAOSSOLVERENGINE_API void UnregisterChaosEvents();
93
94private:
95
96 // contains the set of properties that uniquely identifies a reported collision
97 // Note that order matters, { Body0, Body1 } is not the same as { Body1, Body0 }
98 struct FUniqueContactPairKey
99 {
100 const void* Body0;
101 const void* Body1;
102
103 friend bool operator==(const FUniqueContactPairKey& Lhs, const FUniqueContactPairKey& Rhs)
104 {
105 return Lhs.Body0 == Rhs.Body0 && Lhs.Body1 == Rhs.Body1;
106 }
107
108 friend inline uint32 GetTypeHash(FUniqueContactPairKey const& P)
109 {
110 return uint32((PTRINT)P.Body0 ^ ((PTRINT)P.Body1 << 18));
111 }
112 };
113
114 FCollisionNotifyInfo& GetPendingCollisionForContactPair(const void* P0, const void* P1, bool& bNewEntry);
116 TMap<FUniqueContactPairKey, int32> ContactPairToPendingNotifyMap;
117
118 FChaosPendingCollisionNotify& GetPendingChaosCollisionForContactPair(const void* P0, const void* P1, bool& bNewEntry);
120 TMap<FUniqueContactPairKey, int32> ContactPairToPendingChaosNotifyMap;
121
123 TArray<FChaosPendingCollisionNotify> PendingChaosCollisionNotifies;
124
126 TArray<FCollisionNotifyInfo> PendingCollisionNotifies;
127
128public:
134 CHAOSSOLVERENGINE_API void RegisterForCollisionEvents(UPrimitiveComponent* ComponentToListenTo, UObject* ObjectToNotify);
135 CHAOSSOLVERENGINE_API void UnRegisterForCollisionEvents(UPrimitiveComponent* ComponentToListenTo, UObject* ObjectToNotify);
136
137 CHAOSSOLVERENGINE_API void RegisterForBreakEvents(UPrimitiveComponent* Component, FOnBreakEventCallback InFunc);
138 CHAOSSOLVERENGINE_API void UnRegisterForBreakEvents(UPrimitiveComponent* Component);
139
140 CHAOSSOLVERENGINE_API void RegisterForRemovalEvents(UPrimitiveComponent* Component, FOnRemovalEventCallback InFunc);
141 CHAOSSOLVERENGINE_API void UnRegisterForRemovalEvents(UPrimitiveComponent* Component);
142
143 CHAOSSOLVERENGINE_API void RegisterForCrumblingEvents(UPrimitiveComponent* Component, FOnCrumblingEventCallback InFunc);
144 CHAOSSOLVERENGINE_API void UnRegisterForCrumblingEvents(UPrimitiveComponent* Component);
145
146private:
147
148 UPROPERTY()
149 TMap<TObjectPtr<UPrimitiveComponent>, FChaosHandlerSet> CollisionEventRegistrations;
150
151 UPROPERTY()
153
154 UPROPERTY()
156
157 UPROPERTY()
159
160
161 float LastCollisionDataTime = -1.f;
162 float LastBreakingDataTime = -1.f;
163 float LastRemovalDataTime = -1.f;
164 float LastCrumblingDataTime = -1.f;
165
166 void DispatchPendingCollisionNotifies();
167
168 template <typename EventIterator>
169 void FillPhysicsProxy(FPhysScene_Chaos& Scene, TArray<UObject*>& Result, EventIterator& It);
170
171 TArray<UObject*> GetInterestedProxyOwnersForCollisionEvents();
172 TArray<UObject*> GetInterestedProxyOwnersForBreakingEvents();
173 TArray<UObject*> GetInterestedProxyOwnersForRemovalEvents();
174 TArray<UObject*> GetInterestedProxyOwnersForCrumblingEvents();
175
176 // Chaos Event Handlers
177 void HandleCollisionEvents(const Chaos::FCollisionEventData& CollisionData);
178 void HandleBreakingEvents(const Chaos::FBreakingEventData& BreakingData);
179 void HandleSleepingEvents(const Chaos::FSleepingEventData& SleepingData);
180 void HandleRemovalEvents(const Chaos::FRemovalEventData& RemovalData);
181 void HandleCrumblingEvents(const Chaos::FCrumblingEventData& CrumblingData);
182
183};
184
185
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
TFunction< void(const FChaosRemovalEvent &)> FOnRemovalEventCallback
Definition ChaosGameplayEventDispatcher.h:35
TFunction< void(const FChaosBreakEvent &)> FOnBreakEventCallback
Definition ChaosGameplayEventDispatcher.h:23
TFunction< void(const FChaosCrumblingEvent &)> FOnCrumblingEventCallback
Definition ChaosGameplayEventDispatcher.h:47
FPlatformTypes::PTRINT PTRINT
A signed integer the same size as a pointer.
Definition Platform.h:1148
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
const bool
Definition NetworkReplayStreaming.h:178
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UCLASS(...)
Definition ObjectMacros.h:776
#define USTRUCT(...)
Definition ObjectMacros.h:746
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition PhysScene_Chaos.h:116
Definition Array.h:670
Definition AndroidPlatformMisc.h:14
Definition UnrealString.h.inl:34
Definition ChaosEventListenerComponent.h:25
Definition ChaosGameplayEventDispatcher.h:81
Definition Object.h:95
Definition SkeletalMeshComponent.h:307
Definition EventsData.h:97
Definition EventsData.h:64
Definition EventsData.h:204
Definition EventsData.h:161
Definition EventsData.h:175
Definition BodyInstance.h:320
Definition ChaosGameplayEventDispatcher.h:28
FOnBreakEventCallback BreakEventCallback
Definition ChaosGameplayEventDispatcher.h:32
Definition ChaosEventType.h:84
Definition ChaosEventType.h:151
Definition ChaosGameplayEventDispatcher.h:62
Definition ChaosGameplayEventDispatcher.h:73
FChaosPhysicsCollisionInfo CollisionInfo
Definition ChaosGameplayEventDispatcher.h:74
TSet< TObjectPtr< UObject > > NotifyRecipients
Definition ChaosGameplayEventDispatcher.h:75
Definition ChaosNotifyHandlerInterface.h:16
Definition ChaosEventType.h:131
Definition PhysicsPublic.h:91
Definition ChaosGameplayEventDispatcher.h:52
FOnCrumblingEventCallback CrumblingEventCallback
Definition ChaosGameplayEventDispatcher.h:56
Definition ChaosGameplayEventDispatcher.h:40
FOnRemovalEventCallback RemovalEventCallback
Definition ChaosGameplayEventDispatcher.h:44
Definition ObjectPtr.h:488