Scriptable objects to make easy Templates!

I have been hard at work making this map application for an imaginary zoo. Currently I am working on the animal information cards that appear when selecting each section of the park. To make this easier and template based, let us make this into a scriptable object!

Creating a new script called “CardModel”, I have it inherit not from Monobehavior, but ScriptableObject. Below we set the template of what we would want within each card, as can be seen with the Africa card above.

The issue now is that because this does not inherit from Monobehavior, you cannot attach it to any Game Objects. Instead we can add the CreateAssetMenu line, and…

… like magic, we can now create objects that are templated to this script!

Each of these scriptable objects can be filled in the inspector and I have created one for each of the cards that I will need.

In a card view script I had created before and we put each of the scriptable objects into the array. Afterwards I create a new method in the script that will take from our variable card, which is an int, and thennnnnn associate that with an OnClick event for each map area’s button!

So for this button, it will call #5 within the array, and what we get is our Monkey Habitat information!

Scriptable objects can be used for a variety of things, items in a game are one! I better keep them in mind for the future.

See you next post!