How to create and use a ScriptableObject in Unity

A ScriptableObject is a simple to use data container and works really well as a template for objects such weapons or armor in an RPG or perhaps even an information window which is what I will go over in this article.

First, create a script for the ScriptableObject with a suitable name:

Open up the script. Replace the inherit of MonoBehaviour with the class ScriptableObject:

Add the public variables for the information that this object/template will contain:

In order to be able to create the ScriptableObjects it needs to be added to an Editor menu:

In the Editor you can now create the ScriptableObject by right-clicking and from the Create menu select the ScriptableObject. You can also access this from the menu on the top bar:

Populate the ScriptableObject with the information needed:

For the application in this article the information window/panel gets populated when opened from a button. To do that create a class with a public function that takes in the ScriptableObject and update the values based on the ScriptableObject:

Lastly, assign this function to an OnClick event and add the corresponding ScriptableObject:

Final result:

Good luck!

--

--

--

Unity / C# Game developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Are MVC, MVP and MVVM really architectural patterns?

AWS PowerTools Layer — How to setup in SAM

K3s — nerdctl [Field Test 1]

Using AA for GBytes heritage

First Steps in ARM Development

Macro picture of a processor connector

How to Fork Safemoon Contracts for Beginners

Deploy the ML model as a REST API with Python and Flask on Azure Cloud

ln Command — Linux

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Niklas Bergstrand

Niklas Bergstrand

Unity / C# Game developer

More from Medium

Developing A New ‘Way of Seeing’ — #ARTGR520

CoreDump: Protonics

A Note on JSX