Unity Architecture: Scriptable Object Pattern

Over the last year I’ve had a side project to discover the merits of different Architectural Patterns by remaking the same game in as many patterns as I can.

I just recently finished remaking this game using the Scriptable Object Pattern and wanted to present my findings.

I’ve written a blog post about it: Unity Architecture: Scriptable Object Pattern | by Simon Nordon | Dec, 2024 | Medium

The code for the existing 3 patterns is also available on GitHub: unity-architecture-patterns/README.md at main · SimonNordon4/unity-architecture-patterns · GitHub

This thread serves as a more informal discussion and I’m curious to know what other people’s experience with this pattern are.

I’m defining ‘Scriptable Object Pattern’ as a framework that extends the function of Scriptable Objects beyond edit-time data. So we’re talking runtime data, events, logic and even update loops.


Pros

  • The most obvious advantage is that it makes dependency management much easier. We can have ‘globally’ accessible data and events without using statics or singletons.

  • They support serialization so we can view data in the editor, using Unity Events and create custom editors.

  • It’s familiar, It just feels like classic unity and is easy to pickup.

  • UI Toolkit integration. Binding any property or field in an SO to your UI with no code. Obviously pretty great.

  • I think Scriptable Object main strengths are as Events, and Data Models, it makes following an MVC pattern easier in classic unity. Generally having your game state not rely on the view makes it easier to debug, test and build in the long term.

  • If you aren’t using singletons, they help avoid Factory Pattern in your game.

  • Unlike Singletons they can be overwritten on a per-instance basis and support inheritance or interfaces.


Cons

  • Asset Management can become chaotic especially if you have hundreds of SOs in your project.

  • They are ‘Singleton-like’ in nature so they’re not so useful for per-instance data, and from what I hear it’s generally not recommended to create them at runtime, have to design around this.

  • Values persist in the editor. Have to write some boiler plate code to manually reset values.

  • Having over reliance can be harder to track bugs. It’s a little difficult to tell which SOs are active or not. Even just have a reference, in a prefab, that might get loaded at some point, will activate the SO. So your game might be running logic that you didn’t intend for.

For example in my test game I have an ‘EnemyDiedEvent’ which talks to an ‘EnemyDirector’ SO which can trigger the ‘SceneLoader’ to load the WinGame.unity scene. So if I was testing different EnemyDirectors, one might load the WinGame Screen when I’m not expecting it to.


Assets

Worth talking about assets available that help with SO pattern.

The big one is SOAP.

Which provides a no-code solution to Scriptable Objects. It’s SO Pattern pushed to the limit. Extremely decoupled and generic. The reason I don’t use it is the aformentioned asset problem. Having an SO for every variable sounds like a nightmare. I also do like grouping my data together where it makes sense, it helps provide structure to my code and I can think about it more as a story.

I’m still interested in remaking the game with this asset, but because it’s paid I wouldn’t be able to showcase it.

Then there are assets that provide SO Databases like this one:

I think something like this is really useful, just a central location to view all your SOs without hunting them down in the project.

Another tool that might help is sub-assets.

This intuitive grouping would probably help keeping the project folder organized.

I’m not sure if any tools provide this functionality, but something that showed which SOs are enabled at runtime would be also be interesting.

Finally, I believe Unity’s cancelled project Gaia was using the Scriptable Object Pattern. It’s a shame it was cancelled it would have been really interesting to see.

What are your thoughts on SO pattern? Do you guys use it?

2 Likes

I’d prefer the Scriptable Object event architecture used for Unity Open Project 1 development. It’s not very GUI-friendly because of the limited use of Unity Event, but it’s pretty debuggable due to its singleton-like architecture and a free asset finder plugin from Unity Asset Store.

I think the one that UOP1 used is great for testing new systems because we can split and combine scripts easily in multiple scenes, but Unity should’ve provided an official asset finder tool since they always recommend the SO event architecture

1 Like

I had forgotten about this game, but yes I think that was the first introduction to Scriptable Object Pattern.

I really hope Unity continues developing games like this, I think it’s important to actually prove their technology.

I just want Unity to show us how to create an online multiplayer open-world game like V Rising with DOTS

1 Like

Not exactly that genre, but most of the technical mechanics are also present in this demo: Megacity Metro – Large-Scale Multiplayer Demo | Unity
.

That would be cool, but I’m not entirely sure Unity knows how to do that either.

For some reason, most DOTS projects are extremely bare bones.