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!



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