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

Custom search engines with Rails

Python Database Dumping

How Much Do Software Testing Metrics Matter?

What are the Challenges & Solutions While Developing Cross-Platform Mobile Apps?

Sorting a List in Java 8

Kafka — A Preamble

Migration from Objective-C to Swift: a case study

OnCollisionEnter Vs. OnTriggerEnter. How are they different and when should you use them?

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

Study Abroad in the US — How Much Will It Cost?


Lessons Learned From 2021: Student Edition

What are Liquid Cooling Fans, and why is it time to switch to them?