UnityLearn – Beginner Programming – Creating a Character Stat System – Pt. 01 – Overview and Creating Scriptable Objects

January 8, 2020

Beginner Programming: Unity Game Dev Courses

Beginner Programming: Unity Game Dev Courses

Unity Learn Course – Beginner Programming

Project Overview

General Overview of Creating Character Stat System Tutorials

  • Defining and Configuring scriptable objects
  • Accessing data inside of scriptable objects
  • Setting up helpful debugging items
  • Scriptable objects inside of monobehaviours

Creating Scriptable Objects

Scriptable Objects Explained

Scriptable objects are very effective for creating designer tools.

Systems Map: image showing the separate pieces of the game system and how they all connect, in a web-like design

SCriptable Objects: data containers of which, we can have multiplie instances

  • Defined by programmer
  • Treated as assets in Unity
  • Easy for designers to work with
  • CANNOT be added to gameObjects as components

The basic template for turning a script to a scriptable object is adding a [CreateAssetMenu()] header to the top of the script and having the class inherit from SCriptableObject. The CreateAssetMenu header is what adds the scriptable object as an option in Unity’s own Asset Menu at the top of the screen. This also holds the information on how it is displayed there.

Again, it is important to note that scriptable objects CANNOT be added to gameObjects as components. This is worked around in the tutorials however by adding them as a field to a Monobehaviour that is located on a gameObject.

Debugging the Aggro Radius

This segment mostly dealt with importing the project if you had not already, and doing some folder organization for these tutorials. They also added a bool to control showing aggro radius of enemies.

Building Your Scriptable Object

The first scriptable object they create is called CharacterStats_SO.
The CreateAssetMenu tag used at the top of the script is directly used to store this information in an item in the drop down menus of Unity itself. This is why there is a fileName and a menuName.

MenuName: This will be the string seen in the drop down menus directly. You can also add a “/” to create a chain of drop downs where the item will be located.

The fields used for CharacterStats_SO:

  • bool setManually: this will determine if the stats were created manually, or created dynamically
  • bool saveDataOnClose: this will determine if data should be serialized, or written to disk, on close
  • The rest are just general player stats fields (health, damage, resistance, etc.)

SUMMARY

These tutorials were just the tip of getting introduced to scriptable objects in Unity. The rest of the tutorials in this set will delve deeper into the topic and how to incorporate them into other Monobehaviours.