

- #SCRIPTABLE OBJECT ARCHITECTURE HOW TO#
- #SCRIPTABLE OBJECT ARCHITECTURE INSTALL#
- #SCRIPTABLE OBJECT ARCHITECTURE MANUAL#
- #SCRIPTABLE OBJECT ARCHITECTURE CODE#
In this case we're working with GameObjects, so we want a GameObjectCollection. This, once again, allows you to debug systems and have them exist independently of each other. A collection is essentially like a C# list, but which exists in the inspector. First thing first, we need to introduce the concept of collections. Once again, we're leaving out the details, you can check the repo if you're curious, but we place cubes using left mouse button and delete them using right mouse button.Īlrighty, it works! Time to add the UI functionality. It teaches you the concept of runtime sets, so let's do it! This sounds kind of silly, but I couldn't come up with a better example ¯\ (ツ)/¯. Next thing we're going to do is to allow our player to place and delete cubes, and have a UI element count how many cubes there are in the game. Note how versatile this is - the player doesn't even have to be present in the scene for this to work, you can test this in a scene that only contains the healthbar. That's it! We can now test the healthbar again, but this time instead of manipulating the fill image directly, we simply manipulate the player's health in the inspector. private FloatReference currentHealth = null private FloatReference maxHealth = null private void Awake ( ) We simply create a component that includes the following snippet We're dealing with data of the type float, so we want to use the reference type called FloatReference.
#SCRIPTABLE OBJECT ARCHITECTURE CODE#
References are what allows us to reference some value from our code without knowing where it comes from - all we care about is reading and writing to it, the rest is handled entirely from Unity's inspector. This leads us to SO-A's next concept: references. For now the only responsibility of this piece of code is to set the current health to maximum when the game starts, but we'll expand it later on to add more complex behaviour. Great! Now we need to tie this together with some code. We're going to do the exact same thing for our players current health, but leave it blank, since it'll be managed by code. We're going to name this asset "PlayerMaxHealth" and set its value to 100 To do so, simply right-click somewhere in your project and select Create > Variables > float. These are both what SO-A calls 'variables', as they store data, and both will be of the type float.įirst, we'll create the max health variable. These assets will define the maximum- and current amount of health the player has. The first thing we're going to do is create two assets. The entire repository is available in the branch called "tutorial", though, in case you want to check it out.
#SCRIPTABLE OBJECT ARCHITECTURE HOW TO#
Everything else, like how to register collisions in Unity, code snippets for code that makes the player move etc. In order to keep the length of this tutorial manageable, I will only describe code and concepts relating to SO-A specifically. This will also give you a fundamental understanding of how using scriptable objects can improve your architecture in terms of decoupling systems and debugging them.

Throughout this tutorial I'll take you through the step-by-step instructions for using the following features of ScriptableObject-Architecture
#SCRIPTABLE OBJECT ARCHITECTURE INSTALL#
+ Install using a single command line command Installation and updating can be tedious
#SCRIPTABLE OBJECT ARCHITECTURE MANUAL#
Updates can take several days to be published, due to manual verification step by Unity. Not properly supported until 2018.1 Unity Asset Store Whether this is a good or bad thing is up to you +/- Assets will be locked, so you can't modify the source code in any way.

+ Assets are kept in a separate section, which reduces clutter in project-view Here's a short guide that explains the pros and cons of each method Unity Package Manager (2018.1+) There are three ways you can install SO-A. You currently need Unity version 2017.3 or higher Installation Instructions The first thing you should do, is ensure your Unity editor version is compatible with SO-A.
