# Issues with Deserializing Engine.

**URL:** https://discourse.kitware.com/t/issues-with-deserializing-engine/1257
**Category:** Pulse Physiology Engine
**Created:** [March 19, 2024, 6:44am UTC](https://discourse.kitware.com/t/issues-with-deserializing-engine/1257 "2024-03-19T06:44:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![NucleusDev](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/n/ba8739/32.png) [@NucleusDev](https://discourse.kitware.com/u/NucleusDev)
#### Post date: [March 19, 2024, 6:44am UTC](https://discourse.kitware.com/t/issues-with-deserializing-engine/1257/1 "2024-03-19T06:44:58Z")

</div>

Lets say i run the engine for a while and the Heart Rate moved as follows  
HR @ 0s : 72  
HR @ 20s : 65  
HR @ 40 s : 50

And i have Serialised and Saved the Engine at each of these event.

After 40s I ask the Engine to LOad (Deserialize) at the state at what it was at 20s

When i Tick the Engine now. The Engine doesnt start at HR 65 , but it will slowly climb from 50 to 65.

Im using UE5 plugin and the SertializeToString and SerializeFromString Function of the Engine,

I also Call Ready Engine after the SerializeFromString Method

I need the engine to snap to the exact state it was and then continue from there. Please advise  
Am i missing something ?

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [March 19, 2024, 11:58am UTC](https://discourse.kitware.com/t/issues-with-deserializing-engine/1257/2 "2024-03-19T11:58:14Z")

</div>

The state files can be writen as json files by providing the `.json` extension to the filename you are serializing to.

You can look at this json file in a text editor.  
Inspect the state file you saved at 20s, you should be able to find the HeartRate field, and confirm it is 65.  
You can also see the ActiveActions in the state

The Pulse explorer is also built with the same libraries in the latest unreal plugin, so you can load that state into the Pulse explorer to see if the state is starting at the point you are expecting it to be at.

The best thing to do, is to reproduce the issue using [our basic unreal app provided in our repository](https://gitlab.kitware.com/physiology/unreal/-/tree/main/e5.3?ref_type=heads).

Other than that, something is obviously not right, but it could be various things.  
You need to try to narrow it down some.

---

<div class="post-metadata">

### Author: ![NucleusDev](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/n/ba8739/32.png) [@NucleusDev](https://discourse.kitware.com/u/NucleusDev)
#### Post date: [March 25, 2024, 6:57pm UTC](https://discourse.kitware.com/t/issues-with-deserializing-engine/1257/3 "2024-03-25T18:57:39Z")

</div>

HI,  
So i Upgraded to the latest version of the UNreal Plugin. I made 2 Functions in the ExamplePulseComponent as Follows

```auto
void UExamplePulseComponent::Save()
{
    bSaveLoad = true;
    m_PulseEngine->SerializeToFile(TCHAR_TO_UTF8(*FPaths::Combine(FPaths::ProjectSavedDir(),"PulseTest.json")));
    bSaveLoad = false;
}

void UExamplePulseComponent::Load()
{
    bSaveLoad = true;
    m_PulseEngine->SerializeFromFile(TCHAR_TO_UTF8(*FPaths::Combine(FPaths::ProjectSavedDir(), "PulseTest.json")));
    bSaveLoad = false;
}

```

When i Call the Deserialize Function the Code hits the Following Breakpoint.

 ![image](https://discourse.kitware.com/uploads/default/original/1X/5222ed89cb4d1345e898a3323a4bb565cabca074.png)

The Call Stack For Reference

```auto
 	Pulse.dll!000001878cebdbf8()	Unknown
>	UnrealEditor-PulseEngine.dll!UExamplePulseComponent::GetVitalMonitorData() Line 151	C++
 	UnrealEditor-PulseEngine.dll!UExamplePulseComponent::execGetVitalMonitorData(UObject * Context, FFrame & Stack, void * const Z_Param__Result) Line 224	C++
 	UnrealEditor-CoreUObject.dll!UFunction::Invoke(UObject * Obj, FFrame & Stack, void * const Z_Param__Result) Line 6665	C++
 	UnrealEditor-CoreUObject.dll!UObject::CallFunction(FFrame & Stack, void * const Z_Param__Result, UFunction * Function) Line 1139	C++
 	[Inline Frame] UnrealEditor-CoreUObject.dll!FFrame::Step(UObject *) Line 477	C++
 	UnrealEditor-CoreUObject.dll!UObject::ProcessContextOpcode(FFrame & Stack, void * const Z_Param__Result, bool bCanFailSilently) Line 3094	C++
 	[Inline Frame] UnrealEditor-CoreUObject.dll!FFrame::Step(UObject *) Line 477	C++
 	UnrealEditor-CoreUObject.dll!UObject::execLet(UObject * Context, FFrame & Stack, void * const Z_Param__Result) Line 2836	C++
 	[Inline Frame] UnrealEditor-CoreUObject.dll!FFrame::Step(UObject *) Line 477	C++
 	UnrealEditor-CoreUObject.dll!ProcessLocalScriptFunction(UObject * Context, FFrame & Stack, void * const Z_Param__Result) Line 1209	C++
 	UnrealEditor-CoreUObject.dll!ProcessScriptFunction<void (__cdecl*)(UObject *,FFrame &,void *)>(UObject * Context, UFunction * Function, FFrame & Stack, void * const Z_Param__Result, void(*)(UObject *, FFrame &, void *) ExecFtor) Line 1039	C++
 	UnrealEditor-CoreUObject.dll!ProcessLocalFunction(UObject * Context, UFunction * Fn, FFrame & Stack, void * const Z_Param__Result) Line 1279	C++
 	[Inline Frame] UnrealEditor-CoreUObject.dll!FFrame::Step(UObject *) Line 477	C++
 	UnrealEditor-CoreUObject.dll!ProcessLocalScriptFunction(UObject * Context, FFrame & Stack, void * const Z_Param__Result) Line 1209	C++
 	UnrealEditor-CoreUObject.dll!UObject::ProcessInternal(UObject * Context, FFrame & Stack, void * const Z_Param__Result) Line 1306	C++
 	UnrealEditor-CoreUObject.dll!UFunction::Invoke(UObject * Obj, FFrame & Stack, void * const Z_Param__Result) Line 6665	C++
 	UnrealEditor-CoreUObject.dll!UObject::ProcessEvent(UFunction * Function, void * Parms) Line 2145	C++
 	UnrealEditor-Engine.dll!AActor::ProcessEvent(UFunction * Function, void * Parameters) Line 1122	C++
 	[Inline Frame] UnrealEditor-PulseEngine.dll!TScriptDelegate<FNotThreadSafeNotCheckedDelegateMode>::ProcessDelegate(void *) Line 447	C++
 	UnrealEditor-PulseEngine.dll!TMulticastScriptDelegate<FNotThreadSafeDelegateMode>::ProcessMulticastDelegate<UObject>(void * Parameters) Line 900	C++
 	[Inline Frame] UnrealEditor-PulseEngine.dll!FPulseOnSimulationStep_DelegateWrapper(const TMulticastScriptDelegate<FNotThreadSafeDelegateMode> &) Line 144	C++
 	[Inline Frame] UnrealEditor-PulseEngine.dll!FPulseOnSimulationStep::Broadcast(UPulsePhysiologyEngine * InParam2, float) Line 30	C++
 	UnrealEditor-PulseEngine.dll!UPulsePhysiologyEngine::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction * ThisTickFunction) Line 378	C++
 	[Inline Frame] UnrealEditor-Engine.dll!FActorComponentTickFunction::ExecuteTick::__l2::<lambda_1>::operator()(float) Line 1090	C++
 	UnrealEditor-Engine.dll!FActorComponentTickFunction::ExecuteTickHelper<`FActorComponentTickFunction::ExecuteTick'::`2'::<lambda_1>>(UActorComponent * Target, bool bTickInEditor, float DeltaTime, ELevelTick TickType, const FActorComponentTickFunction::ExecuteTick::__l2::<lambda_1> & ExecuteTickFunc) Line 4490	C++
 	UnrealEditor-Engine.dll!FActorComponentTickFunction::ExecuteTick(float DeltaTime, ELevelTick TickType, ENamedThreads::Type CurrentThread, const TRefCountPtr<FGraphEvent> & MyCompletionGraphEvent) Line 1088	C++
 	UnrealEditor-Engine.dll!FTickFunctionTask::DoTask(ENamedThreads::Type CurrentThread, const TRefCountPtr<FGraphEvent> & MyCompletionGraphEvent) Line 278	C++
 	UnrealEditor-Engine.dll!TGraphTask<FTickFunctionTask>::ExecuteTask(TArray<FBaseGraphTask *,TSizedDefaultAllocator<32>> & NewTasks, ENamedThreads::Type CurrentThread, bool bDeleteOnCompletion) Line 1265	C++
 	[Inline Frame] UnrealEditor-Core.dll!FBaseGraphTask::Execute(TArray<FBaseGraphTask *,TSizedDefaultAllocator<32>> & CurrentThread, ENamedThreads::Type) Line 866	C++
 	UnrealEditor-Core.dll!FNamedTaskThread::ProcessTasksNamedThread(int QueueIndex, bool bAllowStall) Line 758	C++
 	UnrealEditor-Core.dll!FNamedTaskThread::ProcessTasksUntilIdle(int QueueIndex) Line 660	C++
 	UnrealEditor-Engine.dll!FTickTaskSequencer::ReleaseTickGroup(ETickingGroup WorldTickGroup, bool bBlockTillComplete) Line 573	C++
 	UnrealEditor-Engine.dll!FTickTaskManager::RunTickGroup(ETickingGroup Group, bool bBlockTillComplete) Line 1583	C++
 	UnrealEditor-Engine.dll!UWorld::RunTickGroup(ETickingGroup Group, bool bBlockTillComplete) Line 771	C++
 	UnrealEditor-Engine.dll!UWorld::Tick(ELevelTick TickType, float DeltaSeconds) Line 1530	C++
 	UnrealEditor-UnrealEd.dll!UEditorEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 1924	C++
 	UnrealEditor-UnrealEd.dll!UUnrealEdEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 531	C++
 	UnrealEditor.exe!FEngineLoop::Tick() Line 5825	C++
 	[Inline Frame] UnrealEditor.exe!EngineTick() Line 61	C++
 	UnrealEditor.exe!GuardedMain(const wchar_t * CmdLine) Line 188	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++
 	[Inline Frame] UnrealEditor.exe!invoke_main() Line 102	C++
 	UnrealEditor.exe!__scrt_common_main_seh() Line 288	C++
 	kernel32.dll!00007ffc0fab257d()	Unknown
 	ntdll.dll!00007ffc10a0aa58()	Unknown

```

Should be noted i only added the save and Load funciton. No Modification have been made.  
Also i prevent a Tick wehn the Save load operation is being conducted

Please Advise

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [March 25, 2024, 7:06pm UTC](https://discourse.kitware.com/t/issues-with-deserializing-engine/1257/4 "2024-03-25T19:06:50Z")

</div>

Seems like the CarinaCO2 pointer has not been set  
You probably need to call the [ReadyData](https://gitlab.kitware.com/physiology/unreal/-/blob/main/PulsePhysiologyEngine/Source/PulseEngine/Private/ExamplePulseComponent.cpp?ref_type=heads#L101) method in your ::Load method

I don’t know everything that is happening in your application, so I am limited on what advice I can provide
