Unity Asset Bundle Animations
Objective: Fix animation issues with Android when using Unity asset bundles.
The AR Horse Anatomy app works fine in Unity’s editor and on an Android phone until the HorsePrefab was packaged into a Unity asset bundle. Now the muscle does not display when the next button is pressed, as shown below, the label appears but no muscle.
To troubleshoot, start by opening the package manager window. Select the + icon and choose “add package from git URL…”. Enter the website below into the field and import package.
This will download the Asset Bundle Browser, which adds an AssetBundle Browser menu option under Unity Window menu.
This package allows you to view the content of your asset bundles before you build. As mentioned the current Android build is not animating properly, but he list below shows that two animations and controller are included into the package. The bundle is configured properly.
The Asset Bundle Browser also allows you to choose your build platform. The build platform is set to Android.
When you build to Android the scene needs an animator in the project so that Unity does not strip animations out of the build. When the asset bundle is created, the animation is now in the asset bundle on the Amazon S3 cloud. When Unity builds, it no longer sees an animator so does not load animation components as it tries to minimizes file size. The solution is to add an animator component to any object, in this case the Canvas.
Add a simple animation to the Canvas, such as a UI > image, called Background, setting the color to black and animate the color.a channel to go from 255 to zero so that it fades.
The last point is that the Unity editor needs to use a Standalone Windows build to render properly. If the Unity editor is used to check asset bundles then create a separate asset bundle for the Unity editor. The asset bundle will render for the Android build in the Unity Editor what you see is not the way it will appear on the Android device. In the images below the Unity Editor has a problem with animation, top, but when deployed to an Android device the animation works as intended, bottom. The problem has in fact been solved but appears to still be broken in Unity’s editor. If a Standalone Windows asset bundle is used instead the animations render as intended in Unity’s editor.
This article drew, in part, on information from the following post: