Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Missing Scripts on loading Scene Asset Bundle

Discussion in 'Asset Bundles' started by Skywalker4, Nov 30, 2018.

  1. Skywalker4

    Skywalker4

    Joined:
    Jul 1, 2016
    Posts:
    6
    Hello Everyone,
    I am developing a Unity loader which loads different scene on demand using asset Bundle. The Scene from the asset bundle loads correctly but the scripts attached to the object in the Scene doesn't load and show a warning message "The referenced script (Unknown) on this Behaviour is missing!". Can someone advise a solution to this problem?
     
  2. Roelof

    Roelof

    Joined:
    Jun 25, 2013
    Posts:
    8
  3. Skywalker4

    Skywalker4

    Joined:
    Jul 1, 2016
    Posts:
    6
    Thanks.
    Can you please explain where should I write the code to import another code at runtime, whether It should be inside an asset bundle or in the loader loading the scene asset bundle?
     
  4. Roelof

    Roelof

    Joined:
    Jun 25, 2013
    Posts:
    8
    it can't be in the assetbundle you want to import/load, because you'd need to import and load it in order to do that :p The assetbundle is only a package that contains some data: it won't become meaningfull until you actually import it and load it's contents.

    So you'll probably want to put both the import and load functionality in a scene, which will then know what to do with the content of the assetbundle (load code and then load objects/scene and whatever).
     
  5. Skywalker4

    Skywalker4

    Joined:
    Jul 1, 2016
    Posts:
    6
    I had already tried that. Here is the code snippet. Can you please check were I am going wrong.
    Code (CSharp):
    1.  IEnumerator AssetUrl0(string url) {
    2.        
    3.         if (!assetBundle0)
    4.         {
    5.             Assembly assembly = Assembly.LoadFile(assemblyURL);
    6.             GameObject gameObject = new GameObject();
    7.             System.Type type = assembly.GetType("Rotation");
    8.             gameObject.AddComponent(type);
    9.  
    10.             using (WWW www = new WWW(url))
    11.             {
    12.                 yield return www;
    13.                 if (!string.IsNullOrEmpty(www.error))
    14.                 {
    15.                     Debug.LogError(www.error);
    16.                     yield break;
    17.                 }
    18.                 assetBundle0 = www.assetBundle;
    19.             }
    20.          
    21.             string[] scenes = assetBundle0.GetAllScenePaths();
    22.  
    23.             foreach (string scenepath in scenes)
    24.             {
    25.                 scene0 = Path.GetFileNameWithoutExtension(scenepath);              
    26.                 SceneManager.LoadSceneAsync(scene0, LoadSceneMode.Additive);
    27.  
    28.                 //assetBundle.Unload(false);
    29.                 //SceneManager.UnloadSceneAsync(scene);
    30.             }
    31.         }
     
  6. Roelof

    Roelof

    Joined:
    Jun 25, 2013
    Posts:
    8
    Hmm, loading the scenes (line 21 onward) seems to be right, though you'll get an error if for whatever reason your www request goes wrong.

    I don't think you're actually getting the code from an assetbundle, but you already have a dll ready at some address? I know I've been struggling a bit with the Assembly loading and found the advice to always try and use the 'Load' function like so:

    var name = AssemblyName.GetAssemblyName(filepath);
    var assembly = Assembly.Load(name);

    Also note that when trying to load an assembly that is already loaded (or shares a name with an already loaded assembly) then you will just get the original returned.
     
  7. Skywalker4

    Skywalker4

    Joined:
    Jul 1, 2016
    Posts:
    6
    I am not getting any code from the asset bundle because all the scripts go missing so I am loading the dll from some address. It fetches the dll correctly and game object is attached with the code inside dll but that object is of the main scene whereas I wanted to add the script to asset bundle scene or object.
     
  8. Roelof

    Roelof

    Joined:
    Jun 25, 2013
    Posts:
    8
    Is the name of your imported dll 'Assembly-CSharp'? If it is, then when it tries to import, it will already see an assembly with the same name and not load this new one. You'll need to use assembly definitions to put your code in a different assembly, so you can load it.
     
  9. Skywalker4

    Skywalker4

    Joined:
    Jul 1, 2016
    Posts:
    6
    I have a Rotation.cs script attached to gameobject in asset bundle scene and converted the same script to Rotation.dll. So do you mean I should change the name of the dll?
     
  10. Roelof

    Roelof

    Joined:
    Jun 25, 2013
    Posts:
    8
  11. Skywalker4

    Skywalker4

    Joined:
    Jul 1, 2016
    Posts:
    6
    I think you are getting confused. I have made Rotaion.dll in the visual studio not just changing the name of dll :D
     
  12. Roelof

    Roelof

    Joined:
    Jun 25, 2013
    Posts:
    8
    Hmm, can you post the Rotation class? Is it part of a Unity project or did you make it in a seperate visual studio solution which you built?