Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to Create patches?

Discussion in 'Scripting' started by holykiller, Oct 18, 2016.

  1. holykiller

    holykiller

    Joined:
    Nov 1, 2013
    Posts:
    10
    Hello there i was wondering if anyone could point me to some links to how to create patches for a unity game. I been working on my project for some time now and its getting big and bigger and on every new update i put out everyone needs to download the complete game again even if they had an old version of it ,so i want to add the option to download all the game or just a patch that will apply the new changes to an old version.
    i know there are some plugins on the assets store but i would like to learn how to do it since i don't get any income from my project...
    Thanks!
     
  2. AlucardJay

    AlucardJay

    Joined:
    May 28, 2012
    Posts:
    328
    Great question! :D

    I had this bookmarked for a long time, but when I finally implemented it in Unity5.4.0 , sadly I get the error :

    Error : Failed to initialize player

    Failed to load PlayerSettings (internal index #0).
    Most likely data file is corrupted, or built with mismatching
    editor and platform support versions.


    Looking at all the previous comments, this did once work. Unless I've done something wrong in creating the list of changed files, it seems that there is some kind off ID system now regarding all the files in a build.

    Searching the above error led me to a couple of steam forums, most noticeably for Kerbal Space Program. IIRC Steam uses a type of version control similar to the linked patch method. However the only solutions I read was to completely uninstall/reinstall.

    Here's hoping that you (and all of us) get an answer (fingers crossed)
     
    holykiller likes this.
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Seperate all of the assets out from the game with assetbundles. That way only bits of the game you touch need to be updated.

    New content can be deployed just by sending out a new asset bundle. Changed content can be distributed by updating an asset bundle. Changes to the game code will still require redistribution of the build, but not the assets.

    This system will break if you upgrade your Unity version, but that's typically not done mid project anyway.
     
    Ryiah likes this.
  4. holykiller

    holykiller

    Joined:
    Nov 1, 2013
    Posts:
    10
    i read the code and that's more like an updater i was looking for self contain patches like gamePatchV1ToV2.exe that has all the files that changed on the exe or in a folder. And going back to the link you posted now i see what you were talking about when you say the id system ,its the "downloadList" right? and i think they do so with checksum hash code that checks if the file changed if so download it . or something like that.but again for that to work you would have to put all your project in the hosting page and that's what i don't want to do haha.
    i will try the asset bundle way that BoredMormon was suggesting and see how that goes but still if its posible to do self contain patches that are apply when runned that would be a lot better :)
     
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    If the main goal is simply to diff the current build with the new build, and then apply changes, I would consider using a third party tool for it. Surely there are already programs out there designed to do this?
     
    Ryiah likes this.
  6. AlucardJay

    AlucardJay

    Joined:
    May 28, 2012
    Posts:
    328
    Yeah, but where's the fun in that? ;)
    The learning experience and the satisfaction of crafting a system with the knowledge gained is second-to-none (at least for a mere hobbyist like myself).

    You can also run into other problems using a third-party solution, for example with this asset : It will become more expensive in the long run to deal with a broken tool with little to no support. I highly recommend just looking elsewhere, or figuring out how to just roll your own solution so you don't have to deal with the inevitable dropped support from any Unity store asset.
    So for reliability, continued support, and even just for understanding and controlling what the updater is doing, I personally think it's far more frugal to roll-your-own.

    Even the Unity AssetBundle system keeps changing : https://forum.unity3d.com/threads/new-assetbundle-build-system-in-unity-5-0.293975/
    And finally, the biggest problem with AssetBundles : AssetBundles can contain asset files such as models, materials, textures and scenes. AssetBundles cannot contain scripts. (source: https://unity3d.com/learn/tutorials...undles-and-assetbundle-manager?playlist=17117 )
     
    holykiller likes this.
  7. AlucardJay

    AlucardJay

    Joined:
    May 28, 2012
    Posts:
    328
    Not quite. Basically, you create a list of files that have been modified. Then simply overwrite/replace those files with the most recent. For example, this was the winmerge log I got from 2 separate builds (all I did was change the text in a UI Text object) :
    Code (csharp):
    1. Compare F:\Unity Projects 5-4-0f3\Dead Reckoning\Dead Reckoning Test\Builds\build 0-0-1 with F:\Unity Projects 5-4-0f3\Dead Reckoning\Dead Reckoning Test\Builds\build 0-0-2
    2. 10/09/2016 11:24:21 PM
    3. Filename,Folder,Comparison result,Left Date,Right Date,Extension
    4. drtest_Data,,Folders are different,10/09/2016 9:26:47 PM,* 10/09/2016 11:21:43 PM,
    5. Managed,drtest_Data,Folders are different,10/09/2016 9:26:22 PM,* 10/09/2016 11:21:43 PM,
    6. Assembly-CSharp-firstpass.dll,drtest_Data\Managed,Binary files are different,10/09/2016 9:25:54 PM,* 10/09/2016 11:21:36 PM,dll
    7. Assembly-CSharp.dll,drtest_Data\Managed,Binary files are different,10/09/2016 9:25:55 PM,* 10/09/2016 11:21:38 PM,dll
    8. globalgamemanagers,drtest_Data,Binary files are different,10/09/2016 9:26:00 PM,* 10/09/2016 11:21:40 PM,
    9. level1,drtest_Data,Binary files are different,10/09/2016 9:26:00 PM,* 10/09/2016 11:21:40 PM,
    And then I wrote a parser to clean up the changelog text file to something easier to read for the patch system :
    Code (csharp):
    1. patch
    2. 0.0.0
    3. drtest_Data/Managed/Assembly-CSharp-firstpass.dll
    4. drtest_Data/Managed/Assembly-CSharp.dll
    5. drtest_Data/globalgamemanagers
    6. drtest_Data/level1
    This can be easily tested without even implementing a patch system. Simply copy and replace the specified newer files in a duplicate of the previous build.

    This is where the error occurs. On launching the modified project, that's when the Unity error appears :
    Error : Failed to initialize player
    Failed to load PlayerSettings (internal index #0).
    Most likely data file is corrupted, or built with mismatching editor and platform support versions.


    This happens when the .exe is or is not replaced with the newer version. So somewhere inbetween when that solution was posted and a Unity update, suddenly the build .exe doesn't recognize those replaced files. And searching the project files does not reveal a PlayerSettings filename. So where is this (internal index #0) information embedded? Maybe in PlayerPrefs? Need someone who knows more about the intricate workings of a Unity build to explain how to make this version control type of patch system work. (or if infact it is still even possible in Unity 5.4 and up).
     
  8. AlucardJay

    AlucardJay

    Joined:
    May 28, 2012
    Posts:
    328
    Bueller .... Bueller .... Bueller ....
     
  9. Klaus-Eiperle

    Klaus-Eiperle

    Joined:
    Mar 10, 2012
    Posts:
    41
    --> I had the same error... When a user installs a newer build over an existing, using MSI installer, the exe file of the game itself won't be updated. The rest is working as expected. MSI replaces older files. So, you have to update always the exe file of your game always for preventing these error.