UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ChaosSolversModule.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "HAL/Event.h"
11#include "Async/AsyncWork.h"
13#include "Framework/Threading.h"
14#include "PhysicsCoreTypes.h"
16#include "Chaos/Declares.h"
18#include "Chaos/Defines.h"
20
23{
24public:
25 virtual UClass* GetSolverActorClass() const = 0;
26};
27
30{
31public:
33
34 virtual float GetMinDeltaVelocityForHitEvents() const
35 {
36 return 0.f;
37 }
38
39 virtual bool GetPhysicsPredictionEnabled() const
40 {
41 return false;
42 }
43
44 UE_DEPRECATED(5.5, "GetResimulationErrorThreshold has been renamed, please use GetResimulationErrorPositionThreshold.")
49
51 {
52 return false;
53 }
54
56 {
57 return 0;
58 }
59
61 {
62 return false;
63 }
64
66 {
67 return 0;
68 }
69
71 {
72 return false;
73 }
74
76 {
77 return 0;
78 }
79
81 {
82 return false;
83 }
84
86 {
87 return 0;
88 }
89
90 virtual float GetPhysicsHistoryTimeLength() const
91 {
92 return 0;
93 }
94
96 {
97 return 0;
98 }
99};
100
101namespace Chaos
102{
103 class FPersistentPhysicsTask;
104 class FPhysicsProxy;
105 class FPhysicsSolverBase;
106}
107
108// Default settings implementation
109namespace Chaos
110{
112 {
113 public:
114 };
115
117}
118
120{
122
126
127private:
128
129 // Private so only the module can actually make these so they can be tracked
133 FSolverStateStorage& operator =(const FSolverStateStorage& InCopy) = default;
134 FSolverStateStorage& operator =(FSolverStateStorage&& InSteal) = default;
135
136};
137
138enum class ESolverFlags : uint8
139{
140 None = 0,
141 Standalone = 1 << 0
142};
144
146{
147public:
148
150
152
155
156 CHAOS_API void Initialize();
157 CHAOS_API void Shutdown();
158
164
165
171 CHAOS_API Chaos::FPersistentPhysicsTask* GetDedicatedTask() const;
172
177 CHAOS_API void SyncTask(bool bForceBlockingSync = false);
178
191 CHAOS_API Chaos::FPBDRigidsSolver* CreateSolver(UObject* InOwner, Chaos::FReal InAsyncDt, Chaos::EThreadingMode ThreadingMode = Chaos::EThreadingMode::SingleThread, const FName& DebugName = NAME_None);
192
194
199 {
200 SolverActorClass = InActorClass;
201 SolverActorRequiredBaseClass = InActorRequiredBaseClass;
202 check(IsValidSolverActorClass(SolverActorClass));
203 }
204
206
208
215
218
225
229
235
236#if WITH_EDITOR
242 CHAOS_API void PauseSolvers();
243
250
256
261#endif // #if WITH_EDITOR
262
264 {
265 SolverActorClassProvider = Provider;
266 };
267
268
272 {
273 SettingsProvider = InProvider;
274 }
275
276 void LockSolvers() { SolverLock.Lock(); }
277 void UnlockSolvers() { SolverLock.Unlock(); }
278
283
287
290
291private:
292
294 IChaosSolverActorClassProvider* SolverActorClassProvider;
295
297 IChaosSettingsProvider* SettingsProvider;
298
299 // Whether we actually spawned a physics task (distinct from whether we _should_ spawn it)
300 bool bPersistentTaskSpawned;
301
302 // The actually running tasks if running in a multi threaded configuration.
304 Chaos::FPersistentPhysicsTask* PhysicsInnerTask;
305
306 // Core delegate signaling app shutdown, clean up and spin down threads before exit.
307 FDelegateHandle PreExitHandle;
308
309 // Flat list of every solver the module has created.
311
312 // Map of solver owners to the solvers they own. Nullptr is a valid 'owner' in that it's a map
313 // key for unowned, standalone solvers
315
316 // Lock for the above list to ensure we don't delete solvers out from underneath other threads
317 // or mess up the solvers array during use.
318 mutable FCriticalSection SolverLock;
319
321 UClass* SolverActorClass;
322
324 UClass* SolverActorRequiredBaseClass;
325
327 FGraphEventRef GlobalCommandTaskEventRef;
328
329#if STATS
330 // Stored stats from the physics thread
331 float AverageUpdateTime;
333 float Fps;
334 float EffectiveFps;
335#endif
336
337#if WITH_EDITOR
338 // Pause/Resume/Single-step thread safe booleans.
340 FThreadSafeCounter SingleStepCounter; // Counter that increments its value each time a single step is instructed.
341#endif // #if WITH_EDITOR
342
343 // Whether we're initialized, gates work in Initialize() and Shutdown()
344 bool bModuleInitialized;
345
347 FDelegateHandle OnCreateMaterialHandle;
348 FDelegateHandle OnDestroyMaterialHandle;
349 FDelegateHandle OnUpdateMaterialHandle;
350
351 FDelegateHandle OnCreateMaterialMaskHandle;
352 FDelegateHandle OnDestroyMaterialMaskHandle;
353 FDelegateHandle OnUpdateMaterialMaskHandle;
354};
355
#define check(expr)
Definition AssertionMacros.h:314
ESolverFlags
Definition ChaosSolversModule.h:139
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
#define ENUM_CLASS_FLAGS(Enum)
Definition EnumClassFlags.h:6
EChaosThreadingMode
Definition PhysicsCoreTypes.h:21
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition ChaosSolversModule.h:112
Definition PBDRigidsSolver.h:84
Definition PhysicsSolverBase.h:313
Definition AsyncWork.h:585
Definition ChaosSolversModule.h:146
void UnlockSolvers()
Definition ChaosSolversModule.h:277
CHAOS_API FChaosSolversModule()
Definition ChaosSolversModule.cpp:68
CHAOS_API void StartupModule()
Definition ChaosSolversModule.cpp:99
void RegisterSolverActorClassProvider(IChaosSolverActorClassProvider *Provider)
Definition ChaosSolversModule.h:263
CHAOS_API void OnDestroyMaterial(Chaos::FMaterialHandle InHandle)
Definition ChaosSolversModule.cpp:637
CHAOS_API UClass * GetSolverActorClass() const
Definition ChaosSolversModule.cpp:238
CHAOS_API void DumpHierarchyStats(int32 *OutOptMaxCellElements=nullptr)
Definition ChaosSolversModule.cpp:318
CHAOS_API TArray< const Chaos::FPhysicsSolverBase * > GetSolvers(const UObject *InOwner) const
Definition ChaosSolversModule.cpp:279
CHAOS_API void OnCreateMaterialMask(Chaos::FMaterialMaskHandle InHandle)
Definition ChaosSolversModule.cpp:681
CHAOS_API void OnUpdateMaterial(Chaos::FMaterialHandle InHandle)
Definition ChaosSolversModule.cpp:594
CHAOS_API void ShutdownModule()
Definition ChaosSolversModule.cpp:104
void SetSettingsProvider(IChaosSettingsProvider *InProvider)
Definition ChaosSolversModule.h:271
CHAOS_API void Shutdown()
Definition ChaosSolversModule.cpp:129
CHAOS_API bool IsPersistentTaskRunning() const
Definition ChaosSolversModule.cpp:154
CHAOS_API void OnDestroyMaterialMask(Chaos::FMaterialMaskHandle InHandle)
Definition ChaosSolversModule.cpp:703
CHAOS_API bool IsPersistentTaskEnabled() const
Definition ChaosSolversModule.cpp:149
void LockSolvers()
Definition ChaosSolversModule.h:276
CHAOS_API TArray< Chaos::FPhysicsSolverBase * > GetSolversMutable(const UObject *InOwner)
Definition ChaosSolversModule.cpp:288
CHAOS_API void MigrateSolver(Chaos::FPhysicsSolverBase *InSolver, const UObject *InNewOwner)
Definition ChaosSolversModule.cpp:213
CHAOS_API void GetSolverUpdatePrerequisites(FGraphEventArray &InPrerequisiteContainer)
CHAOS_API Chaos::FPBDRigidsSolver * CreateSolver(UObject *InOwner, Chaos::FReal InAsyncDt, Chaos::EThreadingMode ThreadingMode=Chaos::EThreadingMode::SingleThread, const FName &DebugName=NAME_None)
Definition ChaosSolversModule.cpp:179
CHAOS_API bool IsValidSolverActorClass(UClass *Class) const
Definition ChaosSolversModule.cpp:244
CHAOS_API void OnCreateMaterial(Chaos::FMaterialHandle InHandle)
Definition ChaosSolversModule.cpp:616
CHAOS_API void DestroySolver(Chaos::FPhysicsSolverBase *InState)
Definition ChaosSolversModule.cpp:249
CHAOS_API void Initialize()
Definition ChaosSolversModule.cpp:111
CHAOS_API const TArray< Chaos::FPhysicsSolverBase * > & GetAllSolvers() const
Definition ChaosSolversModule.cpp:274
static CHAOS_API FChaosSolversModule * GetModule()
Definition ChaosSolversModule.cpp:55
CHAOS_API Chaos::FPersistentPhysicsTask * GetDedicatedTask() const
Definition ChaosSolversModule.cpp:159
void SetSolverActorClass(UClass *InActorClass, UClass *InActorRequiredBaseClass)
Definition ChaosSolversModule.h:198
CHAOS_API const IChaosSettingsProvider & GetSettingsProvider() const
Definition ChaosSolversModule.cpp:725
CHAOS_API void SyncTask(bool bForceBlockingSync=false)
Definition ChaosSolversModule.cpp:164
CHAOS_API void OnUpdateMaterialMask(Chaos::FMaterialMaskHandle InHandle)
Definition ChaosSolversModule.cpp:659
Definition IDelegateInstance.h:14
Definition NameTypes.h:617
Definition ThreadSafeBool.h:17
Definition ThreadSafeCounter.h:14
Definition ChaosSolversModule.h:30
virtual float GetResimulationErrorThreshold() const
Definition ChaosSolversModule.h:45
virtual bool GetResimulationErrorLinearVelocityThresholdEnabled() const
Definition ChaosSolversModule.h:70
virtual float GetResimulationErrorLinearVelocityThreshold() const
Definition ChaosSolversModule.h:75
virtual bool GetPhysicsPredictionEnabled() const
Definition ChaosSolversModule.h:39
virtual bool GetResimulationErrorPositionThresholdEnabled() const
Definition ChaosSolversModule.h:50
virtual bool GetResimulationErrorRotationThresholdEnabled() const
Definition ChaosSolversModule.h:60
virtual float GetResimulationErrorPositionThreshold() const
Definition ChaosSolversModule.h:55
virtual float GetMinDeltaVelocityForHitEvents() const
Definition ChaosSolversModule.h:34
virtual float GetResimulationErrorRotationThreshold() const
Definition ChaosSolversModule.h:65
virtual int32 GetPhysicsHistoryCount() const
Definition ChaosSolversModule.h:95
virtual bool GetResimulationErrorAngularVelocityThresholdEnabled() const
Definition ChaosSolversModule.h:80
virtual float GetResimulationErrorAngularVelocityThreshold() const
Definition ChaosSolversModule.h:85
virtual float GetPhysicsHistoryTimeLength() const
Definition ChaosSolversModule.h:90
virtual ~IChaosSettingsProvider()
Definition ChaosSolversModule.h:32
Definition ChaosSolversModule.h:23
virtual UClass * GetSolverActorClass() const =0
Definition Array.h:670
Definition UnrealString.h.inl:34
Definition Class.h:3793
Definition Object.h:95
Definition SkeletalMeshComponent.h:307
FRealDouble FReal
Definition Real.h:22
FInternalDefaultSettings GDefaultChaosSettings
Definition ChaosSolversModule.cpp:46
Definition PhysicalMaterials.h:24
Definition PhysicalMaterials.h:63
Definition ChaosSolversModule.h:357
~FChaosScopeSolverLock()
Definition ChaosSolversModule.h:363
FChaosScopeSolverLock()
Definition ChaosSolversModule.h:358
Definition ChaosSolversModule.h:120
TArray< Chaos::FPhysicsProxy * > ActiveProxies
Definition ChaosSolversModule.h:124
TArray< Chaos::FPhysicsProxy * > ActiveProxies_GameThread
Definition ChaosSolversModule.h:125
Chaos::FPhysicsSolver * Solver
Definition ChaosSolversModule.h:123