Working with Scenes and AssetBundles
In depth learning on Creating and Managing Asset Bundles is found in this course in Motive Academy.
Overview
As projects grow more complex, it’s important to have a consistent workflow for dealing with multiple scenes and AssetBundles. This page describes how to use Unity’s Additive Scene feature to streamline the AssetBundle workflow.
AssetBundle Prefabs in Additive Scenes
Most projects start with a single Scene and all objects and assets are configured inside of that Scene. As the project moves to using AssetBundles, keeping track of which assets are in the Scene and which are bundled becomes a chore. It is also a very common error for an app to be built with the assets built in, requiring another build and lost time.
A better approach is to put all assets that are intended to be bundled into another Scene that is loaded as an additive scene while you are editing it. Do this by right-clicking the Scene in Unity and choosing “Open Scene Additive”:
In this case, the Scene “Scenario 1 Assets” contains all of the assets we configured for that particular scenario.
To Load or Not Load?
While you are developing a scenario, you will often want to work with the local copy of your assets while you are iterating. This may conflict with any assets that are being spawned from AssetBundles. There are two approaches you can use to avoid this while developing:
Disable the Spawn Asset Resource in Storyflow. This is a simple approach that will work, but could potentially impact any other users who are relying on the asset to spawn dynamically.
Set the “Skip Asset Load” property on the World Configuration component. This setting has three options:
Never: select this to always load any assets delivered via AssetBundle.
Editor Only: select this to skip AssetBundle loads when you’re running in the editor.
Always: always skip AssetBundle loads at runtime.
Example
Say you have two large prefabs so far in your project called "Lounge Props" and "Entrance Props." Until this point in your project, you have included both as spawned in assets. But you now realize that both these prefabs can be combined. In that case, it may be best to just load in a new scene with all these combined props.
Here are the steps to create a scene, add in those prefabs, bundle it, and upload it to Storyflow.
Create an empty scene in Unity by clicking Assets → Create → Scene
Name your Scene once it's made
Move it to whatever folder is ideal in the Project window
Right-click on your new Scene and click Open Scene Additive
Delete anything that is automatically added to the new Scene, e.g. Main Camera, Directional Light
Find your prefabs (eg. Lounge/Entrance Props) and drag them from the Project window into the newly made Scene open in your Scene Hierarchy
Save the changes you made to your new Scene, then find it in the Project window and click on it once
You should then be able to see the Inspector's view of your Scene. At the bottom of this view, you should see a dropdown labelled AssetBundle, and the dropdown should be set to None at this point
Click the dropdown and select New…
Write a name in the textbox, and this will be the name for your new Asset Bundle
Ignore the second dropdown that says None for this example
Click Motive → Asset Bundler, then once the window opens, set it up to build and upload your new Scene to the correct folder (One that is not stored in your Unity project) and Storyflow project
Under Select Asset Bundles check only the box for the newly named Asset Bundle you just made
For Select Build Targets, select the appropriate build type that corresponds with your project, typically that is Android. You can also set your default at this time
Click Choose Folder and make sure it is a folder not in your Unity project
Double-check that the App Config being pointed at is the same one you are using for authoring on Storyflow
Login, then enter the provision code displayed under Authenticate Device in your Storyflow project
Select the appropriate Organization, Space and Project that you are authoring in
At the top of the Asset Bundler window, click BUILD AND UPLOAD
Now, in your Storyflow scripts, you can drag in the Load Scene resource, hit the + icon next to Scene, and then you can select the Scene you have uploaded
Related Articles