Search Unity

Feedback Please add reliable reset function for all platform

Discussion in 'Scripting' started by Thaina, Sep 17, 2020.

  1. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,168
    In general, every OS has its own way to close and relaunch application. Which is useful for clearing every state include private static variable in 3rd party, for fresh start application ready for login and/or changing configuration (language and locale for example)

    And so I think it would be better if unity would implement `Application.Reset` function that could make a relaunch with every state cleared like it has been closed from task manager and opened from app icon again

    Is it possible?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Sure it is possible but that's what the operating system is designed for.

    To properly implement anything like this, it would impose the following requirement on EVERY piece of code that you or any third party wrote: they would need to implement a way to respond to such an event and reliably restore all their state, deallocate all their memory, release any peripherals or external resources they may have acquired, and ALL of that would have to happen regardless of what they might already be doing, such as receiving a packet of network traffic. ALL of that would have to work.

    Let the OS do it. And for what you need to reset in a game, put it all in an instance class and make a new one, switch scenes and go on with your life. Unity even lets you do vast amounts of "find all GameObjects and nuke all GameObjects" if you really want to get brutal about it yourself.

    I generally just jump back to the first scene in my game. Done.
     
  3. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,168
    `jump back to the first scene` is not reliable way to reset though. What I mean from the start is I wish unity would implement this function on the OS level

    At least I know what can be done in some platform. In web platform we could just reload page
    In android is a bit more complicate, but unity could unload and queueing reload the game as a library
    In windows we could open new process and exit current process
    In editor we could exit play mode and run play mode again programmatically

    I just don't know about other platform and this task is so tedious. I think it possible for unity to just write platform specific reset function
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Unity and the OS don't operate on the same "level."

    Code (csharp):
    1. gameState = new GameState();
    2. SceneManager.LoadScene(0);
    If you did not design your game to contain state in a single place, how did you implement savegames?!
     
    Joe-Censored likes this.
  5. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,168
    That's what I called unreliable. As I said we could have many static variable especially from third party that we have no control over it. For example I have been very frustrate on facebook initialization. After initial the facebook will keep it static variable and reset my game cannot reset facebook
    Also your suggestion limit our freedom to scatter class and always make everything dependent to that central point hotspot. Your code will never decouple from that. And it just redundant if we could just reset our app

    PS. My game was saving data on cloud database. Data was separated into many places and I don't need to save anything locally. And that's also why I need ability to reset and reload everything