Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by CausticLasagne · Jan 21, 2017 at 07:23 AM · restart game

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nathanthesnooper · Jul 16, 2017 at 06:53 PM 0
Share

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?

avatar image kaarthickiyer · Jul 25, 2017 at 02:28 AM 0
Share

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.

avatar image
3

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();
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CausticLasagne · Feb 04, 2017 at 07:36 PM 0
Share

Exactly. We want to reload EVERYTHING. Scene loading does not solve this issue.

avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CausticLasagne · Jan 21, 2017 at 04:15 PM 0
Share

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.

avatar image Bunny83 CausticLasagne · Jan 21, 2017 at 05:12 PM 0
Share

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?

avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

65 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I created a maze game where the ai uses a pathfinder to find the MainCharacter. I want when the ai touches the MainCharacter(First Person Controller), then reset the game. I have gotten help on my code a few time but the code never works. 2 Answers

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges