Demo project using Addressables package
These samples are broken up into projects based on high level functionality. These are intended as jumping off points for your own development. These have not been tested, and are not guaranteed to work in your situation. They are just examples, to make some concepts easier to understand, or easier to replicate in your own project. Use at your own risk.
Note: Please report any bugs found through the regular bug submission process https://unity3d.com/unity/qa/bug-reporting. For any questions, create a new thread on the Unity Forums https://forum.unity.com/forums/addressables.156/.
Several sample scenes to display functionality surrounding the asset reference class.
AssetReference which will increment the ref count.AssetReference is loaded it keeps a member called .Asset. In this example, you would not want to use the on-complete callback to save off the asset as the loads may not complete in the same order as they were triggered. Thus, it's useful that the reference keeps up with its own loaded asset.GameObject.Instantiate which will not increment the Addressables ref count. These objects still call into Addressables to release themselves, but since they were not instantiated via Addressables, the release only destroys the object, and does not decrement the ref count.OnDestroy or the ref count will survive the closing of the scene.AssetReference class.AssetReference but instantiating via Unity's built in method. This will only increment the ref count once (for the load).AssetReference contains an main asset (editorAsset) and an optional sub object. Certain reference types (for example, references to sprite sheets and sprite atlases) can use sub objects. If the reference uses a sub object, then it will load the main asset during edit mode and load the sub object during runtime.The ins and outs of scene loading.
This example creates an AssetReference that is restricted to having a specific Component.
ReleaseInstance() in the ComponentReference class. To release an instance directly, see our implementation of ReleaseInstance to understand the requirements.2019.3.0a11+ - Sprite demo is back. There was an engine bug causing a crash when loading out of sprite sheets that caused us to remove this demo. This is in 2019.3 alpha, and is being backported to 2019.2 and 2018.4. If you use this demo, and your game crashes, or you get warnings about "gfx" not on main thread, you don't have a fixed version of the platform. There are three sprite access methods currently demo'd in this sample. The on-screen button will change functionality with each click, so you can demo the methods in order.
Referenced in past Unite video(s):
A very simple Unity tutorial that we converted to use addressables. The main code file to look at would be Done_GameController.cs, but in general, this is just meant as a simple project to explore.
Referenced in past Unite video(s):
An example project to show two use cases or workflows for creating "variants". The new build pipeline (Scriptable Build Pipeline) upon which Addressables is built, does not support asset bundle variants. This old mechanism was useful in many instances, so this sample is meant to show how to accomplish similar results for one of those instances.
This sample shows how to create custom AnalyzeRules for use within the Analyze window. Both rules follow the recommended pattern for adding themselves to the UI. There are no scenes to look at in this project, just analyze code.
An example project that shows how to use Unity's Play Asset Delivery API with Addressables. SampleScene (located in 'Assets/Scenes') contains 3 buttons that will load or unload an asset assigned to a specific delivery type.
Note: Play Asset Delivery requires Unity 2019.4+. This project uses Unity 2020.3.15f2.
Use this project as a guide to make custom asset packs. If you don't want to use custom asset packs, follow the instructions in Play Asset Delivery to use the Play Asset Delivery API with the default Addressables configuration.
You can use the default Addressables configuration in this case because the AddressablesPlayerBuildProcessor moves all content located in Addressables.BuildPath to the streaming assets path. Unity assigns streaming assets to the generated asset packs.
Configure Unity to build Android App Bundles. For more information see "Play Asset Delivery".
The sample project uses custom Addressables scripts that make it easier to build and load AssetBundles assigned to asset packs.
Addressables imports most of the scripts automatically, but you need to manually configure some assets in the AddressableAssetSettings:
Build Addressables using the custom "Play Asset Delivery" build script. In the Addressables Groups Window, do Build > New Build > Play Asset Delivery. This script will:
Prepare Addressables to load content from asset packs at runtime (see PlayAssetDeliveryInitialization.cs):
Once configured, you can load assets using the Addressables API (see LoadObject.cs).
Note: To load content from AssetBundles during Play Mode, go to the Addressables Groups window (Window > Asset Management > Addressables Groups) toolbar and select Play Mode Script > Use Existing Build (requires built groups).
When you have configured the build settings according to the Configure Build & Player Settings instructions, go to File > Build Settings and select Build to build the Android App bundle.
Note: You can't upload a development build to the Google Play Console. If you want to upload your App Bundle to the Google Play Console, ensure that you create a release build. For more information, see Build Settings.
The PlayAssetDeliveryBuildProcessor will automatically move bundles to their "{asset pack name}.androidpack” directories in 'Assets/PlayAssetDelivery/Build/CustomAssetPackContent', so that they will be assigned to their corresponding custom asset pack. Then Unity will build all of the custom asset packs along with the generated asset packs.
An example project that shows how to use Unity's On-Demand Resources API with Addressables. LoaderAdr (located in 'Assets/Scenes') contains a script that will load 12 bundles sequentially. Half are locally built and half are on-demand.
The Sample sets asset pack_a to _c as normal Bundles, and the rest, _d to _l as ODR Bundles,
The AdrOdrExt folder contains the files that support using Bundles from ODR.
In Andressables Profiles set the variable 'BuildPathODR' to where you want the ODR Bundles written.
In the Groups Panel for each group you wish to be ODR
Make sure you switch to IOS Target!
In the Addressables Group window switch choose ODR Build Script from the Build menu.
Make sure you switch to IOS Target!
Build the player from the build menu asnormal, the ODR Data should be set up correctly.
You can see it in the UnityData.xcassets file at the bottom of the project.
Demo project using Addressables package
These samples are broken up into projects based on high level functionality. These are intended as jumping off points for your own development. These have not been tested, and are not guaranteed to work in your situation. They are just examples, to make some concepts easier to understand, or easier to replicate in your own project. Use at your own risk.
Note: Please report any bugs found through the regular bug submission process https://unity3d.com/unity/qa/bug-reporting. For any questions, create a new thread on the Unity Forums https://forum.unity.com/forums/addressables.156/.
Several sample scenes to display functionality surrounding the asset reference class.
AssetReference which will increment the ref count.AssetReference is loaded it keeps a member called .Asset. In this example, you would not want to use the on-complete callback to save off the asset as the loads may not complete in the same order as they were triggered. Thus, it's useful that the reference keeps up with its own loaded asset.GameObject.Instantiate which will not increment the Addressables ref count. These objects still call into Addressables to release themselves, but since they were not instantiated via Addressables, the release only destroys the object, and does not decrement the ref count.OnDestroy or the ref count will survive the closing of the scene.AssetReference class.AssetReference but instantiating via Unity's built in method. This will only increment the ref count once (for the load).AssetReference contains an main asset (editorAsset) and an optional sub object. Certain reference types (for example, references to sprite sheets and sprite atlases) can use sub objects. If the reference uses a sub object, then it will load the main asset during edit mode and load the sub object during runtime.The ins and outs of scene loading.
This example creates an AssetReference that is restricted to having a specific Component.
ReleaseInstance() in the ComponentReference class. To release an instance directly, see our implementation of ReleaseInstance to understand the requirements.2019.3.0a11+ - Sprite demo is back. There was an engine bug causing a crash when loading out of sprite sheets that caused us to remove this demo. This is in 2019.3 alpha, and is being backported to 2019.2 and 2018.4. If you use this demo, and your game crashes, or you get warnings about "gfx" not on main thread, you don't have a fixed version of the platform. There are three sprite access methods currently demo'd in this sample. The on-screen button will change functionality with each click, so you can demo the methods in order.
Referenced in past Unite video(s):
A very simple Unity tutorial that we converted to use addressables. The main code file to look at would be Done_GameController.cs, but in general, this is just meant as a simple project to explore.
Referenced in past Unite video(s):
An example project to show two use cases or workflows for creating "variants". The new build pipeline (Scriptable Build Pipeline) upon which Addressables is built, does not support asset bundle variants. This old mechanism was useful in many instances, so this sample is meant to show how to accomplish similar results for one of those instances.
This sample shows how to create custom AnalyzeRules for use within the Analyze window. Both rules follow the recommended pattern for adding themselves to the UI. There are no scenes to look at in this project, just analyze code.
An example project that shows how to use Unity's Play Asset Delivery API with Addressables. SampleScene (located in 'Assets/Scenes') contains 3 buttons that will load or unload an asset assigned to a specific delivery type.
Note: Play Asset Delivery requires Unity 2019.4+. This project uses Unity 2020.3.15f2.
Use this project as a guide to make custom asset packs. If you don't want to use custom asset packs, follow the instructions in Play Asset Delivery to use the Play Asset Delivery API with the default Addressables configuration.
You can use the default Addressables configuration in this case because the AddressablesPlayerBuildProcessor moves all content located in Addressables.BuildPath to the streaming assets path. Unity assigns streaming assets to the generated asset packs.
Configure Unity to build Android App Bundles. For more information see "Play Asset Delivery".
The sample project uses custom Addressables scripts that make it easier to build and load AssetBundles assigned to asset packs.
Addressables imports most of the scripts automatically, but you need to manually configure some assets in the AddressableAssetSettings:
Build Addressables using the custom "Play Asset Delivery" build script. In the Addressables Groups Window, do Build > New Build > Play Asset Delivery. This script will:
Prepare Addressables to load content from asset packs at runtime (see PlayAssetDeliveryInitialization.cs):
Once configured, you can load assets using the Addressables API (see LoadObject.cs).
Note: To load content from AssetBundles during Play Mode, go to the Addressables Groups window (Window > Asset Management > Addressables Groups) toolbar and select Play Mode Script > Use Existing Build (requires built groups).
When you have configured the build settings according to the Configure Build & Player Settings instructions, go to File > Build Settings and select Build to build the Android App bundle.
Note: You can't upload a development build to the Google Play Console. If you want to upload your App Bundle to the Google Play Console, ensure that you create a release build. For more information, see Build Settings.
The PlayAssetDeliveryBuildProcessor will automatically move bundles to their "{asset pack name}.androidpack” directories in 'Assets/PlayAssetDelivery/Build/CustomAssetPackContent', so that they will be assigned to their corresponding custom asset pack. Then Unity will build all of the custom asset packs along with the generated asset packs.
An example project that shows how to use Unity's On-Demand Resources API with Addressables. LoaderAdr (located in 'Assets/Scenes') contains a script that will load 12 bundles sequentially. Half are locally built and half are on-demand.
The Sample sets asset pack_a to _c as normal Bundles, and the rest, _d to _l as ODR Bundles,
The AdrOdrExt folder contains the files that support using Bundles from ODR.
In Andressables Profiles set the variable 'BuildPathODR' to where you want the ODR Bundles written.
In the Groups Panel for each group you wish to be ODR
Make sure you switch to IOS Target!
In the Addressables Group window switch choose ODR Build Script from the Build menu.
Make sure you switch to IOS Target!
Build the player from the build menu asnormal, the ODR Data should be set up correctly.
You can see it in the UnityData.xcassets file at the bottom of the project.