# The Addressables / scriptable object headache

**URL:** <https://discussions.unity.com/t/the-addressables-scriptable-object-headache/1547615>\
**Category:** Addressables\
**Tags:** Addressables, unspecified-version, Question\
**Created:** [November 4, 2024, 10:02am UTC](https://discussions.unity.com/t/the-addressables-scriptable-object-headache/1547615 "2024-11-04T10:02:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt\_unity236](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@matt\_unity236](https://discussions.unity.com/u/matt_unity236)\
**Post date:** [November 4, 2024, 10:02am UTC](https://discussions.unity.com/t/the-addressables-scriptable-object-headache/1547615/1 "2024-11-04T10:02:01Z")

</div>

So I have something of a cautionary tale and request for help at the same time.

I built my entire game using scriptable object game-events which is fairly standard practise so i understand. Unfortunately I didn’t fully understand the mechanics of addressables (i still don’t) since the learning material scattered around the IOT is somewhat inconsistent and incomplete. What I did was added these game events to my addressables groups and every script which needed to invoke those events (not the event listeners) referenced them via script rather than by referencing in the editor using async loading.

Running this in play-mode in the editor worked great. So i blindly stumbled on adding hundreds of these script-only references to my game events. Imagine my surprise when I did a test build and none of my events were being raised, but at the same time, no exceptions were being thrown.

It seems that (and I’m only guessing here) that because in every script that invoked these events I loaded them what I was presumably doing was creating separate copies of the event for each script and thus none of them would work since the listeners would be registered with the original event not the copies.

Now to debug this whole mess I’ve switched to using the build version of my addressables and rebuild them after any major changes, but even having removed the use of addressables from many scripts which invoked these events and using proper references to the scriptable object instead, much of my functionality is still non functional presumbly because my events are still listed in the addressables group.

SO before I waste yet more time unpicking this mess by removing references etc, I’m curious what others think would be the best steps to take. I could continue to remove the events from the addressables group since they don’t exactly take up much memory and don’t really need to be addressables, or should i try to fix my async loading of the events so that all scripts refer to the same object?

---

<div class="post-metadata">

**Author:** ![spiney199](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/spiney199/32/880897_2.png) [@spiney199](https://discussions.unity.com/u/spiney199)\
**Post date:** [November 4, 2024, 10:16am UTC](https://discussions.unity.com/t/the-addressables-scriptable-object-headache/1547615/2 "2024-11-04T10:16:58Z")

</div>

Sounds like you’re facing asset duplication when you have assets used in both addressable and non-addressable contexts. This same behaviour happens in Asset bundles as Addressables is just a wrapper around the old system.

If you’re using addressable, **ALL** your assets need to be addressable, otherwise you’re going to be facing this asset duplication issue across your entire project.

You can also see where duplication will happen with the Analyze window:

 ![image](https://europe1.discourse-cdn.com/unity/original/4X/d/d/1/dd1be387dbb8dc0362af38ef903af65d93cc61e0.png)

This isn’t to say that you have to load everything one by one via addressables. So long as all your assets are organised into addressable groups, loading/unloading scenes will manage all the asset dependencies and asset reference counting. You only need a single non-addressable scene to boot-strap your project.

---

<div class="post-metadata">

**Author:** ![matt\_unity236](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@matt\_unity236](https://discussions.unity.com/u/matt_unity236)\
**Post date:** [November 4, 2024, 10:41am UTC](https://discussions.unity.com/t/the-addressables-scriptable-object-headache/1547615/3 "2024-11-04T10:41:35Z")

</div>

Thanks for the response. I’m honestly starting to consider just binning addressables altogether. it’s feeling rather like they’re more hassle than they’re worth for a small project like this. I think the only reason i started using them was because I misinterpreted their purpose at first. I initially thought it was going to be a handy way of decoupling game objects from scriptable objects by always referring to them by their address instead of using references in the editor.

---

<div class="post-metadata">

**Author:** ![spiney199](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/spiney199/32/880897_2.png) [@spiney199](https://discussions.unity.com/u/spiney199)\
**Post date:** [November 4, 2024, 10:44am UTC](https://discussions.unity.com/t/the-addressables-scriptable-object-headache/1547615/4 "2024-11-04T10:44:45Z")

</div>

Yeah it’s not about decoupling, but more about memory management and remote content delivery (ergo, DLC).

I honestly mostly just use it because I prefer being able to reference scenes via an inspector, and load/unload them clearly with regular C# async code. But other packages like Localisation use it, so having everything already set up for addressables will be a boon when it comes time to implement such a package.

---

<div class="post-metadata">

**Author:** ![matt\_unity236](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@matt\_unity236](https://discussions.unity.com/u/matt_unity236)\
**Post date:** [November 4, 2024, 12:07pm UTC](https://discussions.unity.com/t/the-addressables-scriptable-object-headache/1547615/5 "2024-11-04T12:07:34Z")

</div>

I think I need to spend some more time looking for decent tutorials and educational material. YouTube is a bit of a minefield and UDemy is terrible for out-of-date content

---

<div class="post-metadata">

**Author:** ![Darkpainter](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/darkpainter/32/903476_2.png) [@Darkpainter](https://discussions.unity.com/u/Darkpainter)\
**Post date:** [November 4, 2024, 7:58pm UTC](https://discussions.unity.com/t/the-addressables-scriptable-object-headache/1547615/6 "2024-11-04T19:58:32Z")

</div>

Sound like i have the same problem. After some troubleshooting I found out it had nothing to do with addressables. Instead, scriptable objects which are set as property are NULL for the first 2-5 frames after Awake/Start call. But only in Windows builds, in Editor they work as expected.  
I tested this with Unity 6000.0.23f1 and 6000.0.25f, it did not work. But in unity 2022 it works just fine.

Try to check if they are NULL before using them.

---

<div class="post-metadata">

**Author:** ![matt\_unity236](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@matt\_unity236](https://discussions.unity.com/u/matt_unity236)\
**Post date:** [November 5, 2024, 9:49pm UTC](https://discussions.unity.com/t/the-addressables-scriptable-object-headache/1547615/7 "2024-11-05T21:49:49Z")

</div>

So I’ve come up with a solution which fixes the problem and removes any need to use scriptable objects. It might feel a little archaic but i feel like simple is probably best.

I created a static class called eventmanager which has only one function, to store events and listeners in a dictionary and tell the listeners of a specific event when it’s invoked. This means I can use a string as the event which is the key for the dictionary and a list of listeners as the value in the dictionary.

```auto
using System.Collections.Generic;

public static class StaticEventManager
{
    private static Dictionary<string, List<NewEventListener>> eventListeners = new Dictionary<string, List<NewEventListener>>();

    public static void Register(string eventName, NewEventListener listener)
    {
        if (!eventListeners.ContainsKey(eventName))
        {
            eventListeners[eventName] = new List<NewEventListener>();
        }

        eventListeners[eventName].Add(listener);
    }

    public static void Unregister(string eventName, NewEventListener listener)
    {
        if (eventListeners.ContainsKey(eventName))
        {
            eventListeners[eventName].Remove(listener);

            if (eventListeners[eventName].Count == 0)
            {
                eventListeners.Remove(eventName);
            }
        }
    }

    public static void InvokeEvent(string eventName)
    {
        if (eventListeners.ContainsKey(eventName))
        {
            foreach (NewEventListener listener in eventListeners[eventName])
            {
                listener.OnInvoke();
            }
        }
    }
}

```

my listeners are simple components which register with the static class on enable and de-register on disable. All the listeners need is a register method, an unregister method, a string for the event name and a unityevent for the response.

```auto
using UnityEngine;
using UnityEngine.Events;

public class NewEventListener : MonoBehaviour
{
    [SerializeField]
    string EventName;
    public UnityEvent Response;

    private void OnEnable()
    {
        StaticEventManager.Register(EventName, this);
    }

    private void OnDisable()
    {
        StaticEventManager.Unregister(EventName, this);
    }

    public void OnInvoke()
    {
        Response.Invoke();
    }
}

```

This is build friendly, and simple enough that even a moron like me can debug it if things go wrong.
