Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 York Wu · Sep 05, 2013 at 09:38 AM · assetbundlepatch

Problem using assetbundle to patch a game.

Hello! We're develop a game using assetbundle so that scene can be changed by modifying them. But it is another story when I need to patch my code.

Originally I thought it not possible to patch code via assetbundle. After I read this, it now seems to work. I made a test to verify if it works. After building first working version, I modified one of the scripts and build the assembly, and made an assetbundle. Then I load the assetbundle by the following script. It is already in the first working version of the game.

 using UnityEngine;
 using System.Collections;
 
 public class LoadBinaryScript : MonoBehaviour {
     
     public string assemblyBundleUrl = "http://my_site/some_path/barrel.patch";
     public string patchFilename = "CodePatch";
     public GUIText logMessage;
     public string[] replacedClasses;
     
     IEnumerator GetPatch()
     {
         WWW patch = new WWW(assemblyBundleUrl);
         yield return patch;
         if(patch.error != null){
             Debug.Log("Patch download error: "+patch.error);
             logMessage.text = "Patch download error: "+patch.error;
             yield break;
         }
         Debug.Log("Patch loaded.");
         TextAsset ta = patch.assetBundle.Load(patchFilename, typeof(TextAsset)) as TextAsset;
         if(ta == null){
             Debug.Log("Patch not exist: "+patchFilename);
             logMessage.text = "Patch not exist: "+patchFilename;
             yield break;
         }
         Debug.Log("Patch code extracted.");
         logMessage.text = "Patch code extracted.";
         var assembly = System.Reflection.Assembly.Load(ta.bytes);
         
         bool err = false;
         for(int i=0;i<replacedClasses.Length;++i){
             var typ = assembly.GetType(replacedClasses[i]);
             if(typ == null){
                 logMessage.text = "Script not found: "+replacedClasses[i];
                 err = true;
                 break;
             }
         }
         if(!err){
             logMessage.text = "All scripts found.";
         }
     }    
     
     // Use this for initialization
     void Start () {
         Debug.Log ("LoadBinaryScript Start()");
         
         StartCoroutine(GetPatch());
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 

After restarting the test game, it seems successful. Both "Patch loaded" and "Patch code extracted" are printed, and even "All scripts found" are shown on screen. However, when the modified script runs, it still print message stating it the old version. Is there something missing? Or isn't it working this way? Can anyone help me?

Comment
Add comment · Show 3
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 Benproductions1 · Sep 05, 2013 at 10:25 AM 0
Share

Your script works, but I think you are mistaken as to what it does. What you are doing is loading the assembly you downloaded, but from what I can see, you do nothing with it. The "loaded" assembly, will not replace any of the scripts you have, it will simply be a dynamically loaded assembly, which is only useful with reflection code if you want to do anything game wise (of which I see nothing)

A better method would be to have the assembly replace an already existing assembly in the project, meaning you should be able to use it like any other standard, included assembly :)

avatar image York Wu · Sep 06, 2013 at 01:10 AM 0
Share

Thanks a lot. So is the only way updating a script to rebuild the whole project and to replace the DLLs?

avatar image Benproductions1 · Sep 06, 2013 at 01:17 AM 0
Share

Well, you could use a whole lot of reflection in your code, but that would be horribly slow. Besides those two options, you could also take the newly built dll's and only patch them :)

0 Replies

· Add your reply
  • Sort: 

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

17 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

Related Questions

Android texture AssetBundles loading problem 0 Answers

Using Scripts in AssetBundles 0 Answers

Blender 2.71 - FBX exporter is not compatible 5 Answers

Including scripts in AssetBundles on iOS 1 Answer

is that possible to load prefab from script. 1 Answer


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