Not getting callbacks for some System Events

I have a component that needs to run some code in the event of game/editor/program shutdown.

I have set up the component to get callbacks from ISystemEventListener and CrySystemEventBus.

I am receiving some events to my component, so I am pretty sure it is setup correctly, but I am not receiving the shutdown related events.

Headers are included:

#include <ISystem.h> // for ISystemEventListener #include <CrySystemBus.h> // for CrySystemEventBus

Classes are inherited

	class myComponent
: public AZ::Component
, public CrySystemEventBus::Handler
, public ISystemEventListener

Functions are overridden:


void OnSystemEvent(ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam) override;
void OnCrySystemPreInitialize(ISystem& system, const SSystemInitParams& systemInitParams) override;
void OnCrySystemShutdown(ISystem& system) override;

For example, this is working:

	void myComponent::OnCrySystemCVarRegistry()
{
AZ_TracePrintf("myComponent", "OnCrySystemCVarRegistry");
}

This is not working:

	void myComponent::OnCrySystemShutdown(ISystem& system)
{
AZ_TracePrintf("myComponent", "OnCrySystemShutdown");
}

In the below, ESYSTEM_EVENT_GAME_POST_INIT, SYSTEM_EVENT_GAME_POST_INIT_DONE, and ESYSTEM_EVENT_EDITOR_GAME_MODE_CHANGED are working, but ESYSTEM_EVENT_LEVEL_UNLOAD, ESYSTEM_EVENT_FULL_SHUTDOWN, ESYSTEM_EVENT_FAST_SHUTDOWN are not working.

	void myComponent::OnSystemEvent(ESystemEvent event, UINT_PTR wparam, UINT_PTR lparam)
{
switch (event)
{
case ESYSTEM_EVENT_GAME_POST_INIT:
AZ_TracePrintf("myComponent", "ESYSTEM_EVENT_GAME_POST_INIT");
break;
case ESYSTEM_EVENT_GAME_POST_INIT_DONE:
AZ_TracePrintf("myComponent", "ESYSTEM_EVENT_GAME_POST_INIT_DONE");
break;
case ESYSTEM_EVENT_EDITOR_GAME_MODE_CHANGED:
AZ_TracePrintf("myComponent", "ESYSTEM_EVENT_EDITOR_GAME_MODE_CHANGED");
break;
case ESYSTEM_EVENT_LEVEL_UNLOAD:
AZ_TracePrintf("myComponent", "ESYSTEM_EVENT_LEVEL_UNLOAD");
break;
case ESYSTEM_EVENT_FULL_SHUTDOWN:
AZ_TracePrintf("myComponent", "ESYSTEM_EVENT_FULL_SHUTDOWN");
break;
case ESYSTEM_EVENT_FAST_SHUTDOWN:
AZ_TracePrintf("myComponent", "ESYSTEM_EVENT_FAST_SHUTDOWN");
break;
}
}

To see if it might be something with my component, I went and added AZ_TracePrintf to Starter Game in StarterGameGemModule.cpp in the OnSystemEvent function, and I also didn’t see any log output. I’ve also tried adding breakpoints and none of those were triggered.

Is there something I am missing here? Thanks for the help!

@Binky_LMBR

@Amonster_LMBR

@Scott_LY

Any updates? Thanks.

@Amonster_LMBR

@Scott_LY

@Binky_LMBR

Apologies for the massive delays @Yeshua – I’ve poked a few peers to assist in this topic, ASAP! Hang tight :slight_smile:

Hi @Yeshua,

Shutdown events are actually being reworked to a certain extent. Right now, shutdown events are skipped to do an immediate shutdown, allowing the OS to handle the memory de-allocation. This is handy for speed, but obviously creates problems if you are looking for a shutdown event. If you need a specific shutdown event, you can look for where Quit() is called (in the C++) and build from there. We’re hoping to provide some more details soon regarding the rework, but in the meantime, let me know if you have additional questions!

@Chronos

Thanks for the info. I try to avoid altering the engine/editor source wherever possible, but in this case it looks like I’ll have to do so or wait until you have something to share.

Thanks for the response.