| 303 | // --- Control API --- |
| 304 | |
| 305 | void AMjReplayManager::StartRecording() |
| 306 | { |
| 307 | if (bIsReplaying) |
| 308 | StopReplay(); |
| 309 | |
| 310 | GetLiveFrames().Empty(); |
| 311 | ActiveSessionName = LiveSessionName; |
| 312 | bIsRecording = true; |
| 313 | bCacheValid = false; |
| 314 | bFirstFrameLogged = false; |
| 315 | CachedJointNames.Empty(); |
| 316 | |
| 317 | // Refetch Manager if BeginPlay's fetch lost the race against |
| 318 | // AAMjManager::Instance being set. Without this, recording |
| 319 | // silently captures zero frames because the OnPostStep hook |
| 320 | // below never installs. |
| 321 | if (!Manager) |
| 322 | { |
| 323 | Manager = AAMjManager::GetManager(); |
| 324 | } |
| 325 | |
| 326 | // Re-register the PostStep callback (it gets cleared by StopRecording) |
| 327 | // Sets OnPostStep directly rather than RegisterPostStepCallback -- replay |
| 328 | // needs exclusive control of the callback, not append-to behavior. |
| 329 | if (Manager && Manager->PhysicsEngine) |
| 330 | { |
| 331 | Manager->PhysicsEngine->OnPostStep = [this](mjModel* m, mjData* d) { |
| 332 | this->OnPostStep(m, d); |
| 333 | }; |
| 334 | } |
| 335 | else |
| 336 | { |
| 337 | UE_LOG(LogURLabReplay, Warning, |
| 338 | TEXT("ReplayManager: StartRecording called but no Manager / PhysicsEngine — frames will not be captured.")); |
| 339 | } |
| 340 | |
| 341 | UE_LOG(LogURLabReplay, Log, TEXT("ReplayManager: Started Recording")); |
| 342 | } |
| 343 | |
| 344 | void AMjReplayManager::StopRecording() |
| 345 | { |