- Home /
How to restart application
I'd like to restart the whole game, not loading another level. I would think that launching a new instance on a new thread, and then terminating the current thread would be a cheap restart function, but from what I hear, unity is single threaded.
Ideas?
Answer by CausticLasagne · Jan 21, 2017 at 04:20 PM
Good solution @tanoshimi. I found a solution on my own before reading your post, so here is my results for those also looking to do the same as me.
System.Diagnostics.Process.Start(Application.dataPath.Replace("_Data", ".exe")); //new program Application.Quit(); //kill current process
The magic words to restart your app. Best placed in a void or something and called when you need to restart. Make sure you have access to the directory and execute permissions, or you'll get an AccessDenied
exception or something.
I believe all of the solutions have some downsides... Replacing _Data
is GENIUS, but it does not handle renamed executables; However I don't know if the game will run in the first place if the executable is renamed.
$$anonymous$$ake sure to add OS support! Linux's executables are .x86 and .x86_64, $$anonymous$$ac's are...........idk I think .app?
This is what i was looking for. But i cannot restart using the same way more than 2 times. The second time i try to restart it shows player is already running.
Answer by tanoshimi · Jan 21, 2017 at 09:27 AM
I don't quite understand why you'd want to do this rather than simply reload the first scene - launching a whole new instance of the game is going to cause all the resources in memory to be unloaded and reloaded again, for example. But have you tried something like:
Process.Start(Application.dataPath + "/../YourGameName.exe");
Application.Quit();
Exactly. We want to reload EVERYTHING. Scene loading does not solve this issue.
Answer by shellash · Jan 21, 2017 at 09:16 AM
Hello!
Unity does not give us API to restart app, so it looks like there are no way to do this. Yes, Unity is single-threaded and messing with threads in Unity is bad idea.
Do you really need to restart app? Why not create additional loader scene and make all initialization there?
P.S. Sorry for my English.
No. The game $$anonymous$$UST be reloaded. This is due to technical limitations, no thanks to unity, and the only way to refresh some custom drivers and graphic settings is to restart the game.
Then i would say that's a badly written custom driver and it should be fixed ^^ If that custom driver is made by you / your company, you should consider this. If it's a third-party driver then yes, a restart would probably be the best ^^. Is it even a game or something else?
Answer by nathanthesnooper · Jul 16, 2017 at 06:49 PM
This is the only way I possibly know to restart the app...
What it does is it searches the executable directory, for the executable, and runs it.
The main weakness is that anyone who puts random exe's in their game directory is in for some roulette >:)
public static void restart() {
string[] endings = new string[]{
"exe", "x86", "x86_64", "app"
};
string executablePath = Application.dataPath + "/..";
foreach (string file in System.IO.Directory.GetFiles(executablePath)) {
foreach (string ending in endings) {
if (file.ToLower ().EndsWith ("." + ending)) {
System.Diagnostics.Process.Start (executablePath + file);
Application.Quit ();
return;
}
}
}
}
EDIT: This can handle renaming the executable, so it is perfect for general use.
Answer by Thev2Andy · Mar 13, 2020 at 06:52 PM
For me, I'm using a different splash screen, so I just load the scene again, for example when I clean the player prefs within the game.
Your answer

Follow this Question
Related Questions
My game keeps restarting at random 1 Answer
How do I restart games with more than one level 1 Answer
How reset the Position of all puzzle pieces? 1 Answer
Car Game For School Project 2 Answers