Search Unity

Behaviour missing when creating complex asset bundles

Discussion in 'Scripting' started by antoine.agthe, Jun 26, 2012.

  1. antoine.agthe

    antoine.agthe

    Joined:
    May 18, 2009
    Posts:
    16
    Unity guyz,

    I continue on my Asset Bundle tests.
    I try to create a graph-based structure with some prefab.

    I made the following behaviour :
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Ref : MonoBehaviour
    5. {
    6.     public Ref m_Ref;
    7. }
    I created 11 simple prefabs (A, B, C, D, E, F, G, H, I, J and K) that contain references to some others


    (blue links are normal links, like black ones)

    To build my bundle, I proceeded like that

    Code (csharp):
    1. Build( A ); Build( B ); Build( C );
    2. Push();
    3. Build( D ); Build( E ); Build( F ); Build( G );
    4. Push();
    5. Build( H ); Build( J );
    6. Push();
    7. Build( I ); Build( K );
    8. Pop(); Pop(); Pop();
    I build with CollectDependencies, Deterministic, and CompleteAssets.

    When I try to load a prefab from its bundle, I previously load depending bundles.
    Currently, I can only load and instantiate A, D, H, and I.
    Of the others, I have te following error :
    Then, I add a dependence between A and B, and build like that ;
    Code (csharp):
    1. Build( A );
    2. Push();
    3. Build( B ); Build( C );
    4. Push();
    5. Build( D ); Build( E ); Build( F ); Build( G );
    6. Push();
    7. Build( H ); Build( J );
    8. Push();
    9. Build( I ); Build( K );
    10. Pop(); Pop(); Pop();
    Only G cannot be instantiate.
    And when I load K, referencing G, G is loaded.

    It appears that can only can load a prefab that contains a deep reference to A, that is the first prefab to be "Bundlized".

    Is this a bug or do I missunderstand something ?
     
    Last edited: Jul 17, 2012
  2. Tct1856

    Tct1856

    Joined:
    Jan 22, 2010
    Posts:
    104
    It's not a bug, you probably haven't included a specific script when you were creating an asset bundle.

    So when you load an asset bundle, one of the game objects references that script, but it's not there - and voila - The referenced script on this Behaviour is missing!
     
  3. antoine.agthe

    antoine.agthe

    Joined:
    May 18, 2009
    Posts:
    16
    But aren't scripts supposed to be compiled in the executable ?
    Or do scripts have to be added to bundles ?

    How am I supposed to do that, considering my example ?
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Scripts will not be included in the bundles, but their GUID will still be part of the bundle and then looked up in the executable at runtime.

    Sure that your application is built from the same version as these asset bundles so they reference the same script and sure that the script in question is not one that gets excluded for the target build platform.

    How do you handle the prefab references in the asset bundles? (unity still has no full hierarchical prefabs and the stuff thats present at the time is new in 3.5 and might not be fully working > reporting bugs might be a good idea there with proper explanation on how to recreate it and your test bed)

    The code above only shows a behavior reference, nothing related to the prefab and underlying root game object itself which you would likely 'link' going by your description
     
  5. Tct1856

    Tct1856

    Joined:
    Jan 22, 2010
    Posts:
    104
  6. antoine.agthe

    antoine.agthe

    Joined:
    May 18, 2009
    Posts:
    16
    Of course I use these options.

    Here is the unitypackage taht contains everything needed to reproduce the test.
    Rapidshare link

    All you have to do is click "Assets/Build Bundles" to generate bundles,
    then open the scene,
    specify in "gameObject" inspector which prefab you wanna load,
    then press play.

    Little mistake : B and C are properly loaded.
     
  7. antoine.agthe

    antoine.agthe

    Joined:
    May 18, 2009
    Posts:
    16
    Has anyone tested my sample link ?
    I didn't find the solution yet.
     
  8. antoine.agthe

    antoine.agthe

    Joined:
    May 18, 2009
    Posts:
    16
    I still have the error with Unity 3.5.3
     
  9. Tct1856

    Tct1856

    Joined:
    Jan 22, 2010
    Posts:
    104
    I've looked at the project a bit, and I think something is wrong with your dependencies settings when you build asset bundles, I succesfully loaded A, B, C, D asset bundles, but was failing on E, you marked that E is only dependant on B, try setting that E is dependant on A, B, C, D, and see if you still fail to correctly load E.
     
  10. antoine.agthe

    antoine.agthe

    Joined:
    May 18, 2009
    Posts:
    16
    I don't wanna do this, specially because I don't wanna make E depend on A.
    Imagine that :
    • A, B and C are gun bullets, referencing a "Bullet" MonoBehaviour.
    • D, E, F and G are guns, shooting a given bullet.
      Relation between guns and bullets could be an public array of "Bullet" in the "Gun" MonoBehaviour.
    • H, I, J and K are characters and cars., referencing Guns.
    If gun E cannot shoot A bullet, it won't reference it in the inspector.
    So I don't wanna reference it manually, because I couldn't manitain the system if I have 500 bullets and 150 guns, and if I don't know where Unity3D decided to store my script reference,

    Error is not in my tree.
    Where, in my code, do you think I made a mistake ?
     
  11. antoine.agthe

    antoine.agthe

    Joined:
    May 18, 2009
    Posts:
    16
    OK, it works now.
    The only thing I had to do was to create a bundle contianing the "Ref" script.
    I think Push() makes Unity3D create cross-references on assets of the last built bundle.
    So I "push" each time I create a bundle.

    Code (csharp):
    1. Push();
    2. Build( Ref ); Push();
    3. Build( A ); Push(); Build( B ); Push(); Build( C ); Push();
    4. Build( D ); Push(); Build( E ); Push(); Build( F ); Push(); Build( G ); Push();
    5. Build( H ); Push(); Build( J ); Push(); Build( I ); Push();
    6. Build( K );
    7. PopAll();
     
  12. Lazy

    Lazy

    Joined:
    Oct 5, 2012
    Posts:
    7
    Actually you don't need the Ref bundle for the scripts you used.
    The problem in your previous code is you lacked one push before building A,B,C. Without that D, E, F, G can't find their parent bundles.