Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Data-Driven Items in Unreal using "ScriptableObjects"

A topic by YabDev created 58 days ago Views: 22
Viewing posts 1 to 1

The Problem

In Ryssa Through Time there is going to be an item/inventory system, and it was up to me to implement it. I've done systems like these before in Unity in the past, so this is nothing new to me. However in Unity I made heavy use of the ScriptableObjects feature, while in Unreal (to my knowledge) a feature like this does not exist, so I had to make my own.

The Solution

I first began with creating an Item class derived from Unreal's UObject class. Doing so allows the item to have the UCLASS() macro specifier, which will allow me to tag the item so that blueprint objects can be derived from it. Doing so also allows me to tag the class as abstract, so that only derived versions of it can be created. (This prevents creating an item with no data.)

Within the item class I also define a few parameters that act as the item data. Things such as the item name and description, as well as a texture for the item icon. This is very similar to the way you would set up a ScriptableObject class in Unity. The parameters needed to be tagged with a UPROPERTY(), so that it can be edited in blueprint.

The next step is to actually create some items! I did this by creating a blueprint class that derives from the Item class that was previously defined. Then once in blueprint, each parameter can be defined, exactly like a ScriptableObject! The one thing that really tripped me up at this point was referencing these items. In order to get a reference to the blueprint class, I needed to use a TSubclassOf<Item>, then use the NewObject function to create an instance of the class. From this instance we can get the data stored in the class and use it however we want!