I think I'm misunderstanding how addressables are meant to be used.

I am setting up a little game for fun as an opportunity to learn some of Unity’s newer technologies. At first I was going to use AssetBundles, but then found that they are being replaced by the Addressable’s system so I started looking into it. However, I’m having a hard time migrating what I was doing to this system.

What I had going on was a setup where I put each “World” as it’s own AssetBundle and grouped the levels within.

Long term goal with this would be some sort of system that allows for users to create their own levels and add them to the project (maybe through steam workshop or something, right now this is very much a hobby project)

Then at runtime I would load all of my asset bundles, roughly speaking, I had something akin to this:

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class SceneManager : MonoBehaviour
{
    private List<string> blackList = new List<string> () { "NonLevelData" };
    public Dictionary<string, List<string>> Levels = new Dictionary<string, List<string>> ();

     private void Awake ()
     {
        string[] Bundles = AssetDatabase.GetAllAssetBundleNames ();

        foreach(string bundleName in Bundles)
        {
            if (!blackList.Contains (bundleName))
            {
                string[] bundledLevels = AssetDatabase.GetAssetPathsFromAssetBundle (bundleName);
                Levels[bundleName] = new List<string> (bundledLevels);
            }
        }
    }

    public void LoadData(GameObject root, string assetName, int levelNumber)
    {
        CleanupOldData (root);
        GameObject data = AssetDatabase.LoadAssetAtPath<GameObject> (Levels[assetName][levelNumber]);

        data.transform.SetParent (root.transform);
    }
}

So when I was migrating to an addressable system, I thought: ok, so I can treat each world as it’s own Addressable Group, load the group and find what all of it’s keys are, and that can be used to populate my world/level select menu.

However, as far as I can see, that isn’t what groups are for. Is there any way for me to do something like what I’m doing? Trying to learn the right way to do this in a world with very barebones documentation.

I’m (trying to) doing something similar, we’ve decided to load groups by giving all assets in them the same tag, and then you can just load tag.

I have no idea if this is a good idea though (it’s a bit more fiddly than I’d like, but it seems to work), the documentation really needs some love, and the devs don’t reply too often here.

1 Like

I saw someone suggest that they made a Scriptable Object that contained references to their levels, and had that SO managed with the addressable. I can see an advantage to that because I could also keep level names/display images there without having to load the level lists asyncronously and make sure they all stay ordered properly in my level select.

Basically the SO would be an object that has a World name and a list of “Level Information” objects who would have addresses to screen shots/names/order/level scene references.

It still sort of feels like a haphazard and messy solution, but it shouldn’t be too fiddly.

Ah right, the list of things that actually need loaded. I was thinking I’d make that SO addressable so that the list of mini-games can be updated without needing to update the app - I’ve not built it yet though!

1 Like