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

A Solution To Run Docker in Mac Using Vagrant

How to make a div center aligned?

Accepting Technology (and People) Problems

The simple joy of parity and translation using EF Core and Blazor.

Scraping popular TV-shows on TMDB using Python.

Hypermodern Python 5: Documentation

How to Fork Safemoon Contracts for Beginners

Top 10 Best Desktop Environments for Linux in 2022

Top 10 Best Desktop Environments for Linux in 2022

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

HCDE 451’s Final Project: Flexicure

Axelar covers a large spectrum of the community, the project is created for both developers and…

NFUP, Registered on CMC(CoinMarketCap)

Bringing Agribusinesses On-chain