2D Galaxy Shooter: ScriptableObject

Anurag Chawla
2 min readJun 9, 2021

--

What are ScriptableObject, its use cases and usage…

A ScriptableObject is a data container that one can use to save large amounts of data, independent of class instances. One of the main use cases for ScriptableObjects is to reduce your Project’s memory usage by avoiding copies of values. This is useful if your Project has a Prefab that stores unchanging data in attached MonoBehaviour scripts

The main use cases for ScriptableObjects are:

  • Saving and storing data during an Editor session
  • Saving data as an Asset in your Project to use at run time

To create a ScriptableObject, let’s take an example here — have taken a class WaveConfig inherit from the ScriptableObject class, which we will use later during other use cases..

Class WaveConfig inherit from ScriptableObject

What’s happening here , we are telling Unity that we want to use the features of the ScriptableObject, as it would be with a MonoBehaviour.

But the difference is that you won’t use this script as a normal GameObject in the scene. Instead, the ScriptableObject is treated like any other asset that one create using the unity editor window.

And that is one of the biggest advantages of the scriptable objects, they are assets that you can create/change and hook into Gameobjects to make everything highly decoupled and customizable.

You have also notice that we have assign ScriptableObject to AssetMenu declaring at top of our class as below

[CreateAssetMenu(menuName = “Enemy Wave Configuration”)]

when user click on WaveConfig.cs file, it will show popup menu Create -> Enemy Wave Configuration

and it will create Script -WaveConfig with properties as specified in the WaveConfig.cs as shown above and here we rename the file -Wave1 stored inside the Waves folder

As noticed above we have defined Enemy Prefab, Path Prefab etc these properties are set for one of the Wave1 and one can create as many Waves with different Type(s) of enemy prefab ,their paths where enemies moves …that its easy and configurable..

From here we begin creating new features of our 2D Galaxy shooter— in next article using this ScriptableObject..for below features...

  1. New Enemy Movement
  2. Wave System
  3. New Enemy Type..etc..

--

--

Anurag Chawla
Anurag Chawla

Written by Anurag Chawla

Emerging Technologies - Power Virtual Agents | AI Chatbots | Multi-Cloud & DevOps | UI Technologies - React , Angular | Gaming Technolgies - Unity, XR- AR/VR

No responses yet