ChaosCacheManager is not properly recording the state of each particle when toggling Fields and Anchor Fields in the scene. During my investigations I've noticed that ChaosCacheManager does not record initialization fields, and I suspect this can be the root cause of the unexpected behavior described by the licensee.
The licensee has provided a repro project with a demo scene that displays the unexpected behavior. The demo scene is composed of a Geometry Collection (GC), two FS_AnchorFields (AF) that hold the GC in place at each side, and a FS_MasterField (MF) in the middle of the GC.
Setting ChaosCacheManager (CCM) to CacheMode - RECORD, and playing the scene in the editor (PIE), we verify that after 5 seconds the MF breaks the GC and the middle portion falls to the ground. After 10 seconds a timer (in each AF), spawns a MF in place of the AF and destroys itself. The MFs wake up the particles on each side of the remaining floating GC and make them fall as a single block. Once they hit the ground, they further fragment from the collision. If we stop PIE the session is recorded on the CCM.
Changing CCM to CacheMode - Play and PIE we see the reproduction of the recorded simulation and the unexpected behavior: the middle portion gets fragmented and it's a perfect reproduction, but the sides that originally fall as a block now fragment immediately in the air, some showing strange rotations like their pivots are not at their center, and they all fall down in slow motion.
I've profiled both behaviors using Chaos Visual Debugger. The simulation shows the animation of the falling particles in the Physics World Scene (PWS). The reproduction of the CCM, like expected, does not simulate the particles, so they vanish from the PWS. I would assume they would only show up at the end of the animation or not at all since they were controlled by the animator and not by physics simulation, but they show around the point where the AF are removed and the new MF are added (~10 second into the execution). They display the floating sides fragmented but still floating in the air, and a little later they fall down, animated by the gravity while some parts still remain floating.
I was suspicious that the removal of the AFs or the spawning of MF midway was responsible for breaking the recording, so I changed the setup to have all elements in the scene all the time without deletion, just disabling the AFs and enabling the MFs, but the behavior is the same.
While stepping thru the code I've found a possible culprit in UChaosCache::BuildSpawnableFromComponent():
// make sure we do not have any initialization fields because those may also keep dangling references preventing garbage collection if (UGeometryCollectionComponent* GeometryCollectionComponent = Cast<UGeometryCollectionComponent>(Spawnable.DuplicatedTemplate)) { GeometryCollectionComponent->InitializationFields.Empty(); }
Non-fatal but this is the callstack of the potentially incorrect behavior:
> UnrealEditor-ChaosCaching.dll!UChaosCache::BuildSpawnableFromComponent(const UPrimitiveComponent * InComponent, const UE::Math::TTransform<double> & SpaceTransform) Line 750 C++
UnrealEditor-ChaosCaching.dll!UChaosCache::BeginRecord(const UPrimitiveComponent * InComponent, FGuid InAdapterId, const UE::Math::TTransform<double> & SpaceTransform) Line 416 C++
UnrealEditor-ChaosCaching.dll!AChaosCacheManager::BeginEvaluate() Line 498 C++
UnrealEditor-Engine.dll!AActor::DispatchBeginPlay(bool bFromLevelStreaming) Line 4193 C++
UnrealEditor-Engine.dll!AWorldSettings::NotifyBeginPlay() Line 305 C++
UnrealEditor-Engine.dll!AGameStateBase::HandleBeginPlay() Line 228 C++
UnrealEditor-Engine.dll!AGameModeBase::StartPlay() Line 206 C++
UnrealEditor-Engine.dll!UWorld::BeginPlay() Line 5330 C++
UnrealEditor-Engine.dll!UGameInstance::StartPlayInEditorGameInstance(ULocalPlayer * LocalPlayer, const FGameInstancePIEParameters & Params) Line 568 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::CreateInnerProcessPIEGameInstance(FRequestPlaySessionParams & InParams, const FGameInstancePIEParameters & InPIEParameters, int InPIEInstanceIndex) Line 3141 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::OnLoginPIEComplete_Deferred(int LocalUserNum, bool bWasSuccessful, FString ErrorString, FPieLoginStruct DataStruct) Line 1590 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::CreateNewPlayInEditorInstance(FRequestPlaySessionParams & InRequestParams, const bool bInDedicatedInstance, const EPlayNetMode InNetMode) Line 1853 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::StartPlayInEditorSession(FRequestPlaySessionParams & InRequestParams) Line 2872 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::StartQueuedPlaySessionRequestImpl() Line 1167 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::StartQueuedPlaySessionRequest() Line 1068 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 1902 C++
UnrealEditor-UnrealEd.dll!UUnrealEdEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 550 C++
UnrealEditor.exe!FEngineLoop::Tick() Line 5921 C++
[Inline Frame] UnrealEditor.exe!EngineTick() Line 61 C++
UnrealEditor.exe!GuardedMain(const wchar_t * CmdLine) Line 180 C++
UnrealEditor.exe!LaunchWindowsStartup(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow, const wchar_t * CmdLine) Line 247 C++
UnrealEditor.exe!WinMain(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * pCmdLine, int nCmdShow) Line 298 C++
[External Code]
There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-228459 in the post.
1 |
Component | UE - Simulation - Physics - Destruction |
---|---|
Affects Versions | 5.4.4 |
Target Fix | 5.6 |
Created | Oct 22, 2024 |
---|---|
Updated | Oct 23, 2024 |