Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Windows Game Save

Discussion in 'Editor & General Support' started by tsphillips, Apr 7, 2006.

  1. tsphillips

    tsphillips

    Joined:
    Jan 9, 2006
    Posts:
    359
    Does anyone know whether Unity (through Mono?) provides access to the Windows registry?

    I am looking for a place to save game data, without forcing the user to go through a file chooser. On the Mac I can drop files somewhere under $HOME/Library/, and on Windows I would store the game state in the registry. (Incidentally, how do I learn the location of $HOME from within Unity?)

    Assuming the registry cannot be accessed from Unity, does anyone know of any pseudo-standard game save locations under Windows? (If "My Documents," then how would Unity find that folders absolute file path?)
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,732
    You can always just write a C++ plugin.
    If you have a C++ compiler on windows already it is pretty easy to create those plugins.
     
  3. klindeman

    klindeman

    Joined:
    Jun 13, 2005
    Posts:
    295
    Is there is a solution that doesn't require a C++ plugin? Because that seems like you are just dodging around the question, telling someone how easy they could do it with a Pro-only feature, which is kinda rude.
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,732
    The question is about windows deployment, so one can safely assume to have the Pro version.
    As far as i can see you can only write to the registry from C# directly using p-invoke which is probably harder than writing a c plugin.
    You could of course just put a huge string into the registry using PlayerPrefs.

    To get to the user home directory on mac os x:
    Code (csharp):
    1.  
    2. print("/Users/" + System.Environment.GetEnvironmentVariable("USER"));
    3.  
     
  5. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    ... or even better:
    Code (csharp):
    1.  
    2. print(System.Environment.GetEnvironmentVariable("HOME"));
    3.  
    The home directory is not nessesarily always in /Users/$USER, but that is the system default and most people (i.e. 99.99% of all users) will keep it that way. (An example of users with home in a different place are network users.)

    And here's what you'd do on windows:
    Code (csharp):
    1.  
    2. print(System.Environment.GetEnvironmentVariable("USERPROFILE"));
    3.  
    .. and there is also the APPDATA environment varble on windows.
    Code (csharp):
    1.  
    2. print(System.Environment.GetEnvironmentVariable("APPDATA"));
    3.  
    More windows environment variables: http://kennethhunt.com/archives/000933.html
     
  6. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,537
    Why not just use PlayerPrefs (assuming the functionality you need is enough)? On windows, they are stored in registry (based on your company/product name in player settings).
     
  7. tsphillips

    tsphillips

    Joined:
    Jan 9, 2006
    Posts:
    359
    All good suggestions -- thanks! :)