Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Updating Game While .exe Is Running

Discussion in 'Scripting' started by ShermanZero, Oct 14, 2018.

  1. ShermanZero


    Dec 29, 2016
    Hey guys,

    So I have a potentially tricky question. I've been working on creating an updater for my game. It automatically pulls all the files my game uses to run from my server, and attempts to overwrite the existing ones that are on the user's local machine. The problem I'm facing is a sharing exception, which was unsurprising. Windows can't write/overwrite a file if it already exists and is currently being used. So I've brainstormed for a bit, trying to figure out a workaround for this. Before I spend too much time on it though, I wanted to ask for some advice so I don't overcomplicate everything.

    My first thought is that I don't need to download every single file, but I'm not entirely sure. If you want to check out all the files that my game downloads, you can navigate to the PHP script I have set up to list all the raw contents of the game over at:

    This is essentially what my game pulls, which is then parsed by a function into the actual directory and file locations (function parses data by: $'directory'$ 'file'# !'endOfDirectory'). After that, a coroutine is started to download each individual file. It's not complicated, and it works great... if the game isn't open. Which brings me to another thought, I could create a launcher which acts independently of the game, and then I wouldn't need to worry about files being open when written to.

    Anyway, I'm just looking for some of you guys to toss ideas around with. Let me know if you have any thoughts or advice!

  2. Lurking-Ninja


    Jan 20, 2015
    If you really want to update during use, I would do it in this way:
    - create temp directory
    - download the update in there
    - when next time the exe starts, notices the temp directory
    - instead of normal boot, it quits and run an updater (it can be even a batch file) which applies the update
    - the updater restarts the game, which is now updated

    Why on next run? Because you cannot overwrite anything while in use.
    It's a bad idea to update when the user leaves (if you saw updating windows when you shut down, you know it). It's a risk, the player maybe shutting down the computer.

    Although there is a reason why the launchers are the industry standards. They work.
    ShermanZero likes this.