Download

[Solved] Gameinstance deconstructor called twice

I need to have some things when the application is shutting down.

thougt the gameinstance would be a good place to put the code but found out in the log that the deconstructor gets called twice?

Why?

Anyone else have this?



//Deconstructor
UNitroGameInstance::~UNitroGameInstance()
{
UE_LOG(LogTemp,Warning, TEXT("First call"));
UE_LOG(LogTemp,Warning, TEXT("Second call"));
}


LOG:



[2020.10.19-07.25.50:983] 73]LogExit: Game engine shut down
[2020.10.19-07.25.50:993] 73]LogAISub: UAISubsystem::~UAISubsystem AISubsystem (0000025DFC6699C0), frame # 73
[2020.10.19-07.25.50:993] 73]LogAISub: UAISubsystem::~UAISubsystem AIPerceptionSystem (0000025DFC5F96C0), frame # 73
[2020.10.19-07.25.50:993] 73]LogAISub: UAISubsystem::~UAISubsystem EnvQueryManager (0000025DFC692800), frame # 73
[2020.10.19-07.25.50:995] 73]LogTemp: Warning: First call
[2020.10.19-07.25.50:995] 73]LogTemp: Warning: Second call
[2020.10.19-07.25.50:998] 73]LogTemp: Warning: First call
[2020.10.19-07.25.50:998] 73]LogTemp: Warning: Second call
[2020.10.19-07.25.50:998] 73]LogAISub: UAISubsystem::~UAISubsystem EnvQueryManager (0000025DFF738600), frame # 73
[2020.10.19-07.25.50:998] 73]LogAISub: UAISubsystem::~UAISubsystem AIPerceptionSystem (0000025DFF6620C0), frame # 73
[2020.10.19-07.25.51:016] 73]LogExit: Object subsystem successfully closed.


Well i guess it´s monday morning :rolleyes:

Leaving this post but as solved.

For anyone else
the solution is simple :stuck_out_tongue:




virtual void Shutdown() override;



The destructor is run twice. Once for the instance of the class and once for the Class Default Object (CDO).

You can check for the CDO and return like so:

[FONT=Courier New]if (HasAnyFlags(RF_ClassDefaultObject))
{
return;
}