Create an Addressable Asset from a Loaded Location [IResourceLocation]

Badger Dox
2 min readNov 27, 2019

--

Project & Code

Want assistance? Need to talk some game dev.? Looking for feedback? Join the discussion on Discord

Instantiate an addressable asset and wait for its full creation all in the same method. This will enable you to avoid the nightmares of race conditions when using async features.

Start with creating two new classes CreateAddressablesLoader, Created Assets and add the latter onto your AssetHolder game object.

CreateAddressablesLoader.cs

  • Instantiates an asset based on a given IResourceLocation
  • Wait for an asset to be created
  • Add a created object to a list

CreatedAssets.cs

  • Reference to LoadedAddressableLocations
  • Holds a collection of loaded assets <game objects>
  • Calls to create

Missing LoadedAddressableLocations? Please check out the previous tutorial. Or move onto the next tutorial that illustrates how to create an asset without first having the location loaded.

Open up CreateAddressablesLoader make the script static, don’t forget to remove the monobehaviour. The single method we’ll construct will take in a list of IResourceLocations used to load the assets address. The method will loop through each address and instantiate the accompanying object. Last it will add the object to the generic collection that was also passed in.

Once the previous code has been typed out, open up CreatedAssets. The main calling method will ask for an object to be created and supply the collection it will be added to. The method will be able to wait for the assets to be created and allow for additional operations upon completion.

Back in Unity3d, it’s time to test the code and make sure our asset creation is this simple. TetsAsset

It works! This simple example has some limitations and is meant to explain, not represent best practices. The next tutorial features no interclass coupling or Task.Delay magic []~( ̄▽ ̄)~*. Let’s continue onto the next topic, Creating with a label.

Bonus — Instantiate an addressable(s) in two lines.

Was this post helpful? Please feel free to share it.

Is there anything you’d like more details about? Leave a comment and I’ll respond as thoroughly as possible. Looking for a subject that wasn’t covered, post a suggestion and I’ll get busy filming and creating a write-up.

--

--