Search Unity

Asset Bundle Workflow

Discussion in 'Asset Bundles' started by dreamer-, Mar 14, 2018.

  1. dreamer-

    dreamer-

    Joined:
    Dec 9, 2016
    Posts:
    25
    I am creating asset bundles that contain animation clips(sprite animations).

    What is the best way to handle the sprites that were part of these animation clips?

    As of now I have to remove the sprites that were part of the animation clip and also remove the old asset bundle names before creating new asset bundles. Please suggest a better method.
     
  2. AlienMe

    AlienMe

    Joined:
    Sep 16, 2014
    Posts:
    93
    3 options:
    1) Leave sprites unassigned, and they will be included as dependencies in the animations bundle
    2) Include the sprites in the same bundle with the animation clips
    3) Create a new bundle with the sprites (and load this bundle before the bundle with animation clips).

    1 is less desirable, IMO. We use #3.
     
    dreamer- likes this.
  3. dreamer-

    dreamer-

    Joined:
    Dec 9, 2016
    Posts:
    25
    @AlienMe Thank you for the quick reply.

    By leaving sprites unassigned do you mean not making them a part of the asset bundle with the animation clips. If yes then i am currently following this method.

    Please explain 2) and 3) as I am unable to understand the need for including the sprites also in asset bundle if they are included as dependecies by method 1).

    How can I remove/ignore the sprites form the final build (so that the app size reduces) without affecting the ability to rebuild the asset bundles if needed?
     
    Last edited: Mar 14, 2018
  4. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    if you don't reference (directly or indirectly) your assets from the scene (and they are not in a Resources folder) they will be automatically stripped from the build
     
  5. dreamer-

    dreamer-

    Joined:
    Dec 9, 2016
    Posts:
    25
    @M_R I am unable to find a way to remove references to the sprites used in the animation clip without affecting the ability to rebuild the asset bundles if needed.
     
  6. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    you mean inside the animation? you don't have to remove that.
    stuff in bundles should not be referenced by objects in scene, instead loaded via script at runtime.
    otherwise (1) all the assets are also in scene, and (2) your scene will use whatever you referenced into, meaning rebuilding an AB will not have effect on already deployed players.
     
  7. dreamer-

    dreamer-

    Joined:
    Dec 9, 2016
    Posts:
    25
    @M_R I think I was unable to explain properly.

    I am trying to create an asset bundle "A" that contains animation clips. These animation clips are sprite animations.
    The animation clips(in asset bundle) are loaded via script and assigned to the respective animator controller by making use of animator override controllers(https://docs.unity3d.com/ScriptReference/AnimatorOverrideController.html).

    So shouldn't I be able to remove/ignore the sprites from the build to take advantage of asset bundles and at the same time be able to rebuild the asset bundles when needed. But if I remove the sprites then the animation clips will lose the keyframes containing sprites and as a result any subsequent build will create an incorrect asset bundle for those animation clips.
     
    Last edited: Mar 15, 2018
  8. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    yes, by not referencing those sprites from the build (i.e. scene in build settings, resources, or other assets that are included in the build. this includes sprite atlases)
    you keep the sprites in the project, and keep the references in your bundled clips.
    you should also create a sprite atlas for the bundle.

    you don't remove the sprites from the project. just be careful to not reference them from anywhere that gets included in the build (this can be tricky if you are not organized)

    does the original animator controller have any reference to said clips? or it has empty/null/dummy clips?

    are the sprites packed in an atlas that does get included in the build? that may cause unwanted references

    if it still doesn't work, maybe it's a bug, so send a bug report to Unity.
     
  9. dreamer-

    dreamer-

    Joined:
    Dec 9, 2016
    Posts:
    25
    Yes, the original animator controller has reference to these clips.

    I was thinking of creating 2 animation clips, one would be a dummy clip(and will be included in the animator controller) and the other clip would contain the sprites(but will not be in the animator controller) and will be converted to asset bundles. This way I can avoid referencing and also rebuild asset bundles when needed. But this would double the number of animation clips and project might look messy. Would this be a good way to proceed forward?

    No, the sprites are not packed into an atlas.
     
    Last edited: Mar 15, 2018
  10. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    that's why.
    you (rightfully) include the animator controller in your build, but that pulls the clips that in turn pull the sprites.

    also, probably your game object has a sprite of it's own, that is included in the build.

    you should either unset the animations from the original controller, or create a single empty dummy animation and assign that to every state.

    or you put the object with the animator (as a prefab) in a bundle on it's own and load/instantiate it at runtime
     
    dreamer- likes this.
  11. dreamer-

    dreamer-

    Joined:
    Dec 9, 2016
    Posts:
    25
    Thanks @M_R. I decided to go ahead with using empty dummy animation clips. I have around 50 animation clips that are in asset bundles. But I am not able to use a single dummy clip as some animators have more than one animation clip.