Search Unity

[Official] How Did Asset Bundle Variant Fail To Satisfy Your HD/SD Use Case?

Discussion in '2D' started by ColossalPaul, Dec 23, 2015.

  1. Badalyan

    Badalyan

    Joined:
    Jan 20, 2016
    Posts:
    3
    Hey,

    I'm using Spine animations in my project. The problem is that all the textures for different resolutions are rendered normally on the scenes when I'm using asset bundle variants (sd/hd) except my spine game objects. They lose the reference on skeleton data assets when I'm using other variants rather than the original variant which was used in scene creation. Thus I can't use asset bundles if my spine animations are not working with variants. Do I do something wrong or it is a bug of spine or unity?
     
  2. bryantdrewjones

    bryantdrewjones

    Joined:
    Aug 29, 2011
    Posts:
    147
    @Badalyan: I was having that same issue :) It's fixed in the latest 5.3.5 patch release and the latest 5.4 beta. If you can't upgrade to either of those, you can workaround the issue by calling myAssetBundle.LoadAllAssets<ScriptableObject>() after your bundle has finished downloading.
     
  3. Percy-Pea

    Percy-Pea

    Joined:
    Aug 31, 2014
    Posts:
    62
    Hiya, I too have an issue with ETC1 + Alpha textures when using Spritepacker from within an AssetBundle. In the core project the Alpha channel isnt used so all my sprite renderers have a black border where alpha should be 0. If not packed, the sprites work. This is in 5.3.5 on OSX.

    Oo, and im using Mobile>Particle>Alpha blended as my shader as i find that faster. The gameobjects and materials are in my core project, only the PNGs (some imported as sprites and some as textures) are in my assetbundle.
     
    Last edited: Jul 1, 2016
  4. scaroni-tapps

    scaroni-tapps

    Joined:
    Jul 15, 2016
    Posts:
    5
    Hey guys, i've just started using assetbundles so i could have sd/hd textures in my game, but some of the image references are being hold in an serialized scriptable object in the game folder, then when i read this the refences ignore the loaded variants and show always the same image. The only way i can think of is to load the variant packages and in runtime replace the images referenced by the ones loaded from the bundle. Is there an easier way of doing this?
     
  5. rubeng

    rubeng

    Joined:
    Apr 20, 2013
    Posts:
    36
    if you put your scriptable object in an assetbundle, and load it from there (instead of referencing it directly in the scene, or using resource.load) it should get the images mapped correctly depending on the loaded variant
     
  6. moleary45

    moleary45

    Joined:
    Sep 25, 2015
    Posts:
    1
    I haven't seen these issues mentioned in this thread, so I'll add a few frustrations that I've found while dealing with asset bundle variants.

    With a project that has a bootstrap scene that loads a scene based on a selected/computed variant, I've found that the following issues occur when attempting to run on iOS via xCode.

    1) Any Unity object (Sprite, etc) that is not used in the bootstrap scene cannot be loaded in the variant scene when running on iOS via xCode. You get a "Could not produce class with ID <class_id>" error for each Unity object used in the variant scene that is not used in the bootstrap scene.

    To resolve this, you must turn off the Strip Engine Code option in Player Settings.

    2) Unity-authored (e.g. Canvas, Canvas Scaler, Graphic Raycaster, Image) scripts that are not used in the bootstrap scene cannot be loaded in the variant scene when running on iOS via xCode. You get a "The referenced script on this Behaviour is missing!". There is also a corresponding message that does indicate the Unity Game Object whose Unity-authored script cannot be loaded, but I'm documenting this after I found a resolution. I specifically encountered this scenario for GUI components: Canvas, Panel, Image, EventSystem.

    To resolve this, I created a dummy GUI component in the bootstrap scene for each GUI component that I use in the variant scene and made them non-visible by settings their sizes to 0. It's interesting that Unity has no issue loading scripts I author in the variant scene which are not present in the bootstrap scene, but somehow can't do this for its own scripts.


    Both of these issues seem to be resolvable by the internals of the Unity Asset Bundle APIs and these workarounds shouldn't be necessary. Figuring out what was going wrong and resolving these issues were probably multiple days of work.
     
    Sniffy likes this.
  7. justdizzy

    justdizzy

    Joined:
    Mar 8, 2016
    Posts:
    52
    Instead of turning off stripping, you can add the specific missing classes to link.xml

    http://answers.unity3d.com/questions/49395/objectinstantiate-produces-error-after-i-strip-my.html
     
  8. marche4ever

    marche4ever

    Joined:
    Apr 7, 2014
    Posts:
    4
    the sample project all focused on editor mode, didn't bother show how to use AssetBundleManager from local path or web url. It was so hard to use I was better off just use the WWW myself.
     
  9. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    168
    What do you mean? That the code only works in Editor?

    This is not a requirement to use AssetBundle and our variant example doesn't require this at all. Using this would only make everything murky.
     
  10. zlos

    zlos

    Joined:
    Feb 14, 2013
    Posts:
    2
    I don't see a way to set different import settings per variation for textures. Variations are basically useless without it.
     
  11. Schmekz

    Schmekz

    Joined:
    Mar 11, 2016
    Posts:
    1
  12. YourUncleBob

    YourUncleBob

    Joined:
    Jun 11, 2012
    Posts:
    55
    The question I have with the variants is the asset hookup post load (and having to duplicate the assets). We create all of our bundles in script using BuildAssetBundles, but haven't found any great way to get Variants into our workflow.

    What I want for textures is:
    • One copy of the texture in our game assets
    • An asset bundle for high res textures
    • An asset bundle for low res textures
    • The textures in both bundles share the same unique IDs so that any materials that refer to them work after a load without having to do any additional hookup.
    Do variants support this or do I need to somehow fixup all of the materials to point to the low res variant after a load?

    To achieve this now, what we do instead of using variants to create a low res texture bundle in our bundling script is:
    • Create high res bundle
    • Go through and set the import options on all of the textures to be bundled half the resolution.
    • Reimport the textures
    • Create the low res bundle
    • Restore the import options
    With this, the low res and high res asset bundles both contain the same textures and they have the same names and same unique IDs in both bundles so we don't have to worry about any materials that refer to them. All we do at runtime is decide which bundle to load.

    What I'd love to be able to do at a higher level when creating a bundle is to tell it to reduce all the textures while bundling, or when we provide AssetBundleBuild rather than just supplying a list of assets to include in the bundle, let me provide a list of assets and import options for each of those assets. If I were using alternative low res texture assets rather than just reimporting them with different settings, I'd like to tell the bundler the name of the real asset and the name of the alternative low res asset to use, so I end up with an asset in the bundle with the same name and unique ID of the real asset, but the contents of the low res asset. Maybe this is how variants work, but this isn't the impression I get from the documentation.
     
  13. yourstoryinteractive

    yourstoryinteractive

    Joined:
    Mar 27, 2017
    Posts:
    46
    I have a problem with variants and scriptable objects. My scriptable object has a Sprite member which i'm using for the sake of implementing the sd/hd strategy with the help of variants. If I build the asset bundle such that it contains only this scriptable object I'm getting a duplication of the Sprite both in the asset bundle and in the variant bundle.

    But, if I create a scene and reference the scriptable object inside the scene, then build the asset bundle such that it contains only the scene (which in turn contains the scriptable object), the asset bundle get really tiny (a few kb) which means that the Sprites are now, correctly, stored only in the variant bundles.

    Is that a bug or I'm missing something?
     
  14. zlos

    zlos

    Joined:
    Feb 14, 2013
    Posts:
    2
    That creates problem with content dupliation. Takes more space in version control and you can easily forget to update one or two variations. It's possible to create script that does this job of course. I would like to see this feature in Unity. They already have different import settings per platform, I want this but for variations.
     
  15. PW_Dave

    PW_Dave

    Joined:
    Feb 9, 2017
    Posts:
    30
    Well, nevermind. My prior posts about incorrect variant behavior were invalid. There was a typo in the sample code that I blindly copied and pasted, so it was user error. The AssetBundle Manager sample script LoadVariant.cs has a call to BeginExample() on line 32, right after it starts it as a coroutine. Needless to say, this has undesirable, and time-dependent, effects. I replaced it with the desired Debug.Log message, and all is well.

    I did waste more time on this than I should have, but on the other hand I've learned a lot about the asset bundle system. I also have partially completed tools for specifying and inspecting bundles, which will be rather useful when finished. If I can get them working well enough, I'll try to get permission to share them.

    We do still want to manage our assets in a similar manner as YourUncleBob above, so we do need to do multiple build steps and manage the variants ourselves, since the manifest only contains the variant from the last build step. Sorry about the erroneous posts.
     
    Last edited: Jun 15, 2017
  16. ReaktorDave

    ReaktorDave

    Joined:
    May 8, 2014
    Posts:
    105
    Any news on this?
     
  17. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    168
    The SpriteAtlas has been out since 2017.1 . Note, we are upgrading its documentation to give a more comprehensive overview of its features and how it works. This new system should work for YourUncleBob and similar scenarios.
     
  18. ReaktorDave

    ReaktorDave

    Joined:
    May 8, 2014
    Posts:
    105
    Thanks a lot for giving us an update on this. I didn't expect it to be in the SpriteAtlas-Feature, so I didn't check it's documentation on release.
     
  19. Th0re

    Th0re

    Joined:
    Sep 4, 2015
    Posts:
    32
    Broken link, but this one works.
    https://docs.unity3d.com/Manual/class-SpriteAtlas.html
     
  20. zhujiangbo

    zhujiangbo

    Joined:
    Nov 25, 2013
    Posts:
    4
    hi, your "Variant2.zip" project does not work in unity2018.4.0f1 any more. it work fine in unity5.2.4. can you give me a right version?