Creating a serialized custom class RPG Item Database

Al Heck
2 min readAug 17, 2021

To start, create an item class with a Constructor. We will use 3 variables for now — name, id, and description. This class can be access anywhere similar to a singleton.

Next, let’s create a gameobject that will be our item database. This will be what stores all of our items. We can put in a description of all of the items we pick up using our new class and constructor.

We can also add to our item database using a function and passing in parameters.

This is cool to add items to our database, but how do we retrieve the item? We need to turn it into a return function. It’s the same as a regular function but instead of void, we use item and then at the end, we return item.

Then we create the variable and then run the return function.

If you want to view the items, you need to go to the item class and add [system.serializable] to make the elements viewable in the inspector.

--

--

Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ