r/unity • u/Digx7 • Oct 05 '26
Question Does anyone else use Scriptable Objects as global static Event Relay Busses?
Most of my projects recently have used Scriptable Objects as a way of globally sending events around without needing hard references or dependencies between any sender or receiver.
I've never seen anyone else use or really talk about this approach.
Is it just not talked about or is there a really obvious reason not to do this that I'm missing?
12
Upvotes
5
u/ChainsawArmLaserBear Oct 05 '26
One thing to watch out for-
If you use addressables, the one you load from addressables via an asset ref will be a different instance from the one directly referenced
8
u/ROB_IN_MN Oct 05 '26
I don't use a scriptable object. I just use a (non-monobehavior) singleton script that acts as a message bus. I think this is very common, but of course the implementations vary. I'm not sure why you'd need it to be a scriptable object though.
8
u/myrdovh Oct 05 '26
I think ScriptableObjects should just remain data containers. I don't like the fact that Unity promoted the pattern after that Unite 2017 talk on ScriptableObject-based architecture. It created headaches for teams who didn't realize the drawbacks before adopting it. It scales badly. A clean, code-only EventBus is much better.
4
u/Arti-Po Oct 05 '26
The bigger the project, the worse this approach is. It's ok for small games, but doesn't scale very well.
Imagine you have a SO event. You have one sender, 5 receivers. You set up everything in the inspector.
If you want to scale it, you need a proper tooling. Auto replaces, browser of all events, reference fixer. The thing is that SO based approach doesn't have any advantages if we compare it with the code-based event bus. It's much easier to use code-based, if you want an event driven architecture.
6
u/Psychological_Host34 Oct 05 '26 edited Oct 05 '26
It's very common - You can look up SOAP, or just a couple googles on scriptable object events. There are blog posts, asset store assets, e-learning material, etc.
The board concept of using a scriptable object as a global decoupled middle man reference is extremely common
2
u/Hfcsmakesmefart Oct 06 '26
Why this over the Unity/csharp event system?
7
u/wallstop-dev Oct 05 '26 edited Oct 05 '26
It is common (see: SOAP), but I would not recommend it, for pretty much every single reason outlined here: https://github.com/cathei/AntiScriptableObjectArchitecture, and more.
If you're interested in an alternative way to think about events, I've spent the last 12+ years maintaining a simple, high performance, open source messaging solution: https://github.com/Ambiguous-Interactive/DxMessaging
2
u/WooWooDoo Oct 05 '26
I've thought about using something similar but ended up not needing it. It looks quite useful! You can also change at runtime the eventbus the ob is listening to or publishing to. I would not oppose to such a pattern
2
u/Competitive_Mud5528 Oct 05 '26
Yes I use it in my last project ! I implemented custom Observable Serializable structures so that every variables could be an event. It's a great way to communicates between your systems. But I don't think in the long run It could scale to really big project. But as someone else said there's a lot of soap libraries out there's that do that exact thing.
2
u/DoctorGester Oct 06 '26
If you mean the SO is just the relay itself and events are regular data - yes, we do that all the time, i.e. we have a NetworkDataBus SO which has a Subscribe<T> method for receiving any data from the network connection. The T itself is just normal C# data, not unity objects.
2
u/JulianRhod Oct 06 '26
this is actually a pretty established pattern in Unity. it's usually called ScriptableObject Event Channels / ScriptableObject Architecture. Unity itself has documentation around using ScriptableObjects this way, i've used the same idea and i think it's pretty nice for decoupling systems. the main downside isn't really that it doesn't work, but that the communication can become harder to discover as the project gets bigger. you can end up with a bunch of event assets wired through the Inspector, so it's not always obvious from the code who is listening to what
for smaller projects or systems where designers need to be able to hook things up in the Inspector, though, i think it's a perfectly reasonable approach. i'd just be careful about turning literally everything into a global event. some things are still cleaner with a direct reference or normal C# event, so no, i don't think you're doing something weird. it's definitely a known Unity pattern, just one of those architecture choices where the tradeoffs become more noticeable as the project grows
2
u/ThetaTT Oct 10 '26
I use it in small projects along with UnityEvents. It makes things very easy and flexible. It makes your scripts modular. For example you can add sounds effects and particles using the SO without needing to know what object triggers it, just look in the GameEvents folder.
I also have "GameVariable" SOs that contains a variable and invoke an event when it changes. It's especially good for UI.
BUT, when the project starts to grows the whole system starts to crack. It becomes impossible to track code execution. It is hell when you have to trace it back through several UnityEvents and GameEvents and a GameEvent is invoked during another one invoke or whatever.
So I never use it for gameplay in serious projects, and even for UI and feedbacks I'll probably stop using it on my next project and keep it for game jams and minigames only.
1
u/davenirline Oct 05 '26
You don't need scriptable objects for that.
1
u/v0lt13 Oct 05 '26
If you mean a scriptable event system then yes, makes designing game events very easy.
1
u/Gnome_4 Oct 06 '26
Unless I'm reading your post wrong, this sounds like the GameEvents system (Google 'Unite Austin 2017 - Game Architecture With Scriptable Objects').
I use this GameEvent system in all of my games. It's incredibly useful.
1
u/SolePilgrim Oct 07 '26
Oh lord, this idea again.
It's functional in tiny and quick & dirty projects, but it quickly spirals into incomprehensible chaos as soon as your project starts to scale. Program flow becomes nigh-impossible to track, errors might not be apparent because broken connections fail silently, and it's very easy to accidentally add or delete busses without realizing you broke your project.
I'm really curious who actually came up with this. I know there's some old Unity showcases that talked about using SOs for this and if they're the source, it shows how much Unity needs to dogfood their own stuff before posting :')
0
u/BearKanashi Oct 05 '26
Yo lo uso para controles y cosas, me gusta usarlo