Pros and Cons of Using Scriptable Objects in Unity

preview_player
Показать описание


My Favorite Unity Assets 💯⤵️

* Disclosure: These are affiliate links, which means I'll receive a commission if you use them to make a purchase.
Рекомендации по теме
Комментарии
Автор

I used ScriptableObjects storing configs in my last project. For example: you have 5 different type of enemies, you store all data in ScriptableObjects: texture, health, etc. It's great for decoupling data from logic.

klarnorbert
Автор

You can do a lot of cool staff with scriptable objects. Events system is actually the most valuable. It allows you to completely separate systems from each other and, at the same time, support many to many relations between them. Load your prefabs at runtime or put in whatever scene you like and boom you have them working without any configuration. Using them allows you to almost completely switch to event driven architecture and avoid Update loops...

MicheleKolodi
Автор

Best way to use scriptableobjects IMO is for implementing strategy pattern (drag and drop logic that gets applied on mono behavior referencing them in certain order, good for AI) and as keys to plug in and be used to grab instances (class with current value as well as SO data for min and max and etc) of a variable or apply changes to them. It can also be expanded in this way for events, for example “listen for stat change” gets a reference to a local stat handler on the parent and can subscribe to the events on the stat handler’s “instance” versions of the scriptableobject

ld
Автор

Perfect, someone was just asking me about this and it saves so much time looking for these titles instead of looking for the timestamp in the video haha

CodingWithUnity
Автор

Interesting topic although I don't have the same hard feeling as you guys with applying the observer pattern using SOs.

Something you didn't mention that is I think rather neat when using SOs is that most programming Design Patterns become relevant in asset space. Composite, facade, prototype, factory, flyweight, proxy...

Also using UnityEvent to dispatch events from listeners is one way of doing things, suited in a lot of cases that arent performance intensive and yields absolute flexibility when designing things in the editor, but if the API is done right you may also use delegate calls.

GuillaumeKehren
Автор

The thing is I do not like to use tons of scriptable object für every pieces like IntValue SO Asset for Health. Imagine for health, mana, stamina, speed and so an. Later there is full of scriptableobjects.
But I made own system which will just help to use scriptobject for event if needed.
Example I wrote EventValue<T> class which is serialized and contains automatic value change detection and will fire unity event which is really cool. You can use unityevent. If I declare "public EventValue<int> Health" I can use "Health.Value = 10;" then the unityevent will invoke.
Another one EventActionValue<T> (its from a frame work I wrote) which is same like above but will only show one slot for one scriptableobject. So you cannot setup there multiple things.

I like that setup for ui stuff.

MaZyYTube
Автор

What do you think about "Unite 2016 - Overthrowing the MonoBehaviour Tyranny in a Glorious Scriptable Object Revolution" talk? In my case it showed me new way of using Scriptable Objects - as a sort of 'injected methods' (part from the talk that he uses SO for different kind of destruction), what do you think about that 'pattern'?

Icex
Автор

Regarding the statement of having to lean-in with Zenject and architect the whole project around it - yes, this is true, but I would like to know about any DI system in any software development area where you don't have to do that. Yet they are still widely used. I'm not sure I see this as a problem.

nexxogen
Автор

Jeez, this video is literaly just what I need. Been working on that today for a spline editor !!
Well let me ask for your advice then : How would you save data from a Spline, created and modified in the inspector (not modified in runtime, just editor)? My current structure is basically a graph (because I need multi branching), so I have my Spline class, which has lists of Points and Segments classes. Right now, my Spline class is a scriptable object. Scriptable object is the best option for me rn since it's so easy and convenient, and I have no issue with building my architecture around it, but I do have issues with the asset, for example when I delete my spline in the scene and the asset stays in my files, or vice versa. It requires a special editor button to ensure that the scriptable object asset is deleted along with the game object, which is annoying tbh.


How would you approach it though, to ensure that all the spline data would be saved when closing the editor and building ?

strrb
Автор

So what if Ur creating a card database for a tcg game, is it a wise idea to use it or the old way is better, better what would be the best way

donjohnson
Автор

It would be nice to have a video about common misconceptions, such as being able to save data. This is a common problem I see and Scriptable Objects mislead people into thinking the changes save during runtime since they save in the editor, then they go to build and things break. Using SO's as a database is great, especially for saving and reloading smaller projects that need universal references. The things are pretty nuanced in their use cases that aren't as obvious thanks to how they are implemented in the editor, and some exploration into those would be great for people to hear.

greglyons
Автор

Link for scriptable object architecture reference?

dustypants
Автор

The biggest downsides to Hipple's method is that it's a ton of extra work for programmers. It's a lot of work to put in place these systems instead of just using direct references, but even more so when you get to the end of the talk and find out they had to build entire custom stacks of debugging tools to be able to use this workflow. Even with all this effort orienting your entire architecture around this pattern and building tons of tools, I'm not convinced it's as maintainable and extensible as just doing it in code - the custom tools are just not going to be able to compare with MS and Unity build.

And after all that all you get is the ability for designers to hook up more things to hook up to each other in the GUI? If you get to a point where you are having these issues then you probably need to re-evaluate what you are trying to do.

As for the preferable way to switch between scenes, I would be vary wary of any time this is done at all. My preference is to leverage the hierarchy, load things in to and out of the hierarchy, don't blow it all away. Loading and unloading etc are not good uses of time or resources. It's in memory, keep it in memory.

UCoXrlWjXFOZayVAJCXcg
Автор

ECS (well, DOTS, really) as a viable solution to Scriptable Objects? (eventually? theoretically? I know it's still in development as I write this)

sabatheus
welcome to shbcf.ru