Using ScriptableObjects for player health?

So I’m not great with scriptable objects so I’m not sure if this is a good use of them, but I decided to use a scriptable object for player info/data

public class PlayerInfo : ScriptableObject
{
    public float maxHealth;
    public float health;
    public float shield;

    public BaseClass playerClass;
    public List<BaseAbility> abilities;

    public Controls controls;
}

Currently, I use a health script that has the health values and methods such as SetMaxHealth() and Damage(), but doing the scriptable object approach I’m a bit confused now on how I’d use it. Would I still want to have a health script that controls the health? Or would wanna have a reference to this scriptable object and the health script just adjusts the values in it?

The answer is a big fat “depends”. Scriptable objects are pretty much configuration files for the elements within your game that won’t change. They’re a great fit for holding what bullets come out of a gun or how fast it fires. Maybe in this example you can pick up a rate-of-fire pickup that changes this but the gun still has a base rate of fire which is constant and configured in its associated scriptable object.

So tell me about your player - is this a player that you can choose from a set of possible players who each have different attributes? Do you get to a character select screen and see an array of characters with different maxHealth, shield and abilities? If so then yeah, I’d say scriptable objects are a great fit for this.

However, if your player is a fixed entity with health and shield that changes as the game progresses then maybe scriptable objects aren’t such a great fit. If you’re thinking that scriptable objects would save your player’s health between games then this should instead be handled by a proper saving/loading system since the scriptable objects will not save their changed data between plays once built.

Unless I am misunderstanding it, I don’t think “controls” would be a good fit for inclusion here. I am assuming by this you’re choosing between your input device, e.g. keyboard, mouse, ds4? This seems like something that the player would want to change in settings rather than have as a fixed attribute of the player so is less suited for the scriptable object. Also “health” seems like something that will be set at the start of the game and changed frequently, so similar verdict.

If I’ve made any assumptions that invalidate my points then let me know in the comments and we can discuss :slight_smile: