OnApplicationQuit doesn't work properly.

Hi, when I close my app also in background, my game should start from the beginning, but it doesn’t… Any idea?

Uhm, I don’t think OnApplicationQuit is to blame. You would have to launch your game executable in that function so that it starts again when your game is shut down.

I would highly recommend not to do that, though. I would uninstall any software with such a reboot mechanic. At least make it opt-in.

Use a separate launcher.

It would be helpful to know what platform, but as mentioned, there are very few programs I would want to restart automatically and all of them offer a toggle for it. I can’t think of a single game right now that I would want to restart automatically.

How?

is a hyper casual game, so there isn’t a problem if the game restart…
Also cause if the player exit means that he doesn’t want to play anymore so the game restart. That doesn’t mean that the score is lost.

Depends on the platform, but typically you’d have one application call the other. If when the second application quits you want to relaunch it, you just do the the same way you launched it in the first place.

If you just want the game to restart, you don’t need to close the application. Usually you just reload the scene.

Yes, I know but what if the player quits the game? for that I used on application quit but it doesn’t work properly

What do you mean exactly? Quitting the game completely and restarting it or ending the game and reloading the scene to start over?

OnApplicationQuit is for if the app is closed. If the player chooses to close the game, you don’t want it restarting. They are trying to quit. Either you’re trying to do something that people will get frustrated with. Or you’re thinking something is suppose to do something for you when it isn’t its intended purpose.

1 Like

reloading the scene to start over

Try SceneManager.LoadScene(0)

1 Like

Yes, but SceneManager.LoadScene(0) has to be put in a function. and the unction is onapplicationquit, which doesn’t work as I said before. Yu have an explication??

You know why onapplicationquit doesn’t work?

Who said it doesn’t? Show your code so people can see what you are trying to do. Quitting the game and OnApplicationQuit is really designed for something like saving data before the game closes, not for running the game again.

I say it… how else has to say?

never mind I will find the solution by my own.
Thanks anyways…

How are we supposed to help if you don’t submit your code so that we can figure out what’s wrong with it?

I don’t think OnApplicationQuit works at all on mobile. Google around and it looks like Pause is all you get. That should sort of make sense – you only “quit” when you swipe away a paused – not running – game. It’s not able to run anything in that situation.

OnApplicationQuit was really for PC games. When Unity was first made, PC was the big market.

1 Like