Which method calls automatically when player quit game

I want to call a method when player Quits the game.

Which scripting life cycle method would call?

Thanks for reading.

Try this post Proper way to close / exit game?

I never checked my assumptions, but Scene::onExit and then Application::~Application. Seemed to work well enough for me.

thanks for replying. not worked for me. I want to send message to server on game exit. but it did not work for me

@TankorSmash thanks. But i do not know well it will work in cocos creator JS

you can customized engine.In the “Application::~Application()”,before destroy the script engine and event dispatcher,you can do something customization.
but different platform(win32\android\ios\macos) had different implement
image

usually, I don’t like this way,because not every time you quit game is normal,some times it caused by some crash.in this case,the app can’t calls the method.so the server can’t know the player had gone.
so,usually I realized this feature on servers. the server listened the ticks from client,if the ticks is timeout for some minutes,the server will consider the client is quit and do something.

2 Likes

thanks for replying. i did not get all. Actually i want to send data to server at game close. Can you direct me. :slight_smile: I mean how can i call code from here. May be i did not get your point