Simple Sorting Addressables with MergeMode

Badger Dox
3 min readNov 29, 2019

--

Project & Code

Would you like more help? Need to talk some game dev.? Looking for feedback? Join the discussion on Discord

With Addressables loading and creation now second hand for you. I’m going to throw even more power your way through the automatic convenience of sorting through assets by labels. Unity devs had the forethought to create an incredibly powerful method that does all the legwork for you, Addressables.MergeMode.

  • UseFirst & UseNone load assets containing the first label in the collection.
  • Union grabs all the assets that have any of the provided labels.
  • Intersection loads assets that contain the exact labels provided.

In Unity create a new class, name it SortedCreatedAssets, and drag it onto an object within your hierarchy. Type the base code for the class into your script. If any of this looks foreign look into some of the previous guides for clarity. The method simply creates a list of locations based on the labels that are sent in. Before passing on a location MergeMode will sort through each asset to check if it contains the proper data.

With the example code in your project, don’t forget to add some labels to your list within the inspector. Once your finished press play to test the use of MergeMode.UseFirst. As the name implies it uses the first label in the list and searches for any assets that contain it. The gif. below illustrates any and all objects containing the first string in the list “prefab” being created.

After checking this true in play mode go back to your code and change MergeMode.use first to MergeMode.Union. If you want any objects that any of the labels being passed in this is the function to use. This time expect all the assets to be created, as each in the example project has at least one label contained within the list that is being sorted by MergeMode.

The last way to automatically sort is with MergeMode.Intersection, go ahead and update the line in your code to this now. Intersection only passes on assets that contain all the labels which have been passed in. When using this the gif below should only be able to create the triangle as it has all three labels, in no particular order.

Enjoy even more flexibility and control with these easy sorting methods!

Were these tips usefull? Please feel free to share it wherever you think it would help out others. If that’s a pain consider throwing a clap my way.

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.

--

--