Everhood and Scriptable Objects (Unity)


Intro

In the last devlog about Everhood code architecture, I've mentioned that we use scriptable objects. Let's see what is a scriptable object and how we use them!



What is a Scriptable Object?

A Scriptable Object is a non-monobehaviour class that can be created with CreateAssetMenuAttribute and stored in your project folder. Their main intention is to store data.

The excellent thing about them is that the data stored can be accessed anywhere in the game.
Also, Scriptable Object class empowers you to create multiple instances,this is very useful for things like item stats.

Test it by yourself!


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "Examples/Item")]
public class ItemExample : ScriptableObject
{
    public Sprite itemSprite;
    public float itemCost;
    public float itemDamage;
}





How we use them in Everhood

In our game, we use them as data storage to keep things like settings and player save data.
Our main use case is battle projectiles, we store stats like velocity, damage, and visuals.
Player health is also a scriptable object, this way, all classes that need to know the current player health just need a reference to this scriptable object.
As well, we use them for scene transitions, mainly to have multiple types of fade in and fade out and to be able to create unprecedented scene transitions.
We use them for countless more things, but unfortunately, we have to conclude here, I don't want to spoil anything ;)



Useful links

Architect your game with Scriptable Objects

Game archictecture with Scriptable Objects

Overthrowing the MonoBehaviour Tyranny in a Glorious Scriptable Object Revolution

Scriptable Objects in Unity



//Jordi

Get Everhood

Leave a comment

Log in with itch.io to leave a comment.