1/14/2024 0 Comments Scriptable object architecture![]() While balancing the health and damage values throughout our game, I found it difficult to constantly dig through prefabs to tweak a single number buried deep inside the hierarchy. What I’m about to describe is one such refactor. So what do you do? Iterate and refactor as you go, but also take care not to lose too much time. However, in a month-long game jam, the lack of good engineering practices can cause a lot of friction that gets drawn out over a long time. In a game jam, validating ideas through rapid prototyping takes precedence over good engineering practices. Recently, my team and I took part in a long-form game jam. In the next section, I’ll explain the example that lead me to write this post. So, now we understand the value of Scriptable Objects. If you’ve ever spent hours tweaking values only to have your changes lost in a messy code merger, you understand how beneficial this is. Another advantage is that because Scriptable Objects are composed of simple data and are stored separately from Scene or Prefab files, it’s much easier to avoid merge conflicts when you’re working with version control. Doing this means you can tweak initial values at runtime and keep your changes. By that, I mean the data used to initialize objects rather than the data they reference at runtime. Scriptable Objects are a great way to store authoring data. Depending on what you’re doing, this could either be a benefit or bothersome. One interesting characteristic of Scriptable Objects is that they aren’t reset when exiting play mode. In this way, you could use SOs as states within a Finite State Machine system, for example. For example, you could have several Scriptable Objects, each with a unique OnUpdate method, and swap them out to give objects different behaviours. ![]() So, another application is to switch out algorithms. This modular approach enables designers to quickly try lots of ideas and preserve their experiments as well.Īs I mentioned, Scriptable Objects can hold code as well. Doing so allows you to store multiple variations and swap parameters by dragging different SOs via the Inspector. Now, your MonoBehaviour only needs to reference a single serialized field for Parameter SO. ![]() What I mean by this is, instead of having a MonoBehaviour with several serialized parameters, create a Scriptable Object to hold those serialized parameters instead. Rather than copying values throughout your code or devising complicated ways to access data through a chain of command, you can store information in the Scriptable Object itself and reference that instead.Īdditionally, since they’re Unity assets, you can easily save multiple versions of the same Scriptable Object and swap them out to test different ideas. So, they’re great as a single source of truth. Any number of MonoBehaviours can reference the same Scriptable Object. By the way, shared data includes both code and values. I hope that by explaining their strengths and how I use them, you’ll see how they solve your particular problems.Īt their core, Scriptable Objects are great when you have shared data, especially if you want to assign that data using the Inspector. It would not be easy to enumerate every possible use of Scriptable Objects. So, knowing all this, what makes Scriptable Objects worthwhile? In the next section, I’ll explain some of the situations for which they’re well suited. As I’m sure you know, a single Game Object can have many components attached to it. One last thing to note is that, unlike Game Objects, each Scriptable Object asset only has a single script attached to it. Another difference is that SOs don’t have a hierarchy and can’t be nested the way Game Objects are. ![]() ![]() prefab extension) than a Game Object (which only exists within other files). In that way, they’re more similar to a prefab (which is a file with a. Game Objects only exist within Scenes or Prefabs, whereas a Scriptable Object is an asset that exists on disk. A Scriptable Object is similar to a Game Object with an attached MonoBehaviour, but with a couple of differences. To put it briefly, a Scriptable Object (SOs) is an asset on which you can attach a script. Finally, I’ll give an example problem that I solved using Scriptable Objects. Then, I’ll explain what they do exceptionally well and some of the ways I like to use them. First, I’ll explain what Scriptable Objects are. This article covers the basics of Scriptable Objects and some ways in which they’re helpful. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |