Log67: Getting modular item set for my character in UE5

Log67: Getting modular item set for my character in UE5

A little while ago, I introduced a system/framework which allowed me to model items in my game. This would be a pre-requisite to this post, though I cover some aspects here again.

I now wanted to add a full item set using this framework. I was looking to add the Footman outfit from N-Hance Studio:

Modular item set in game

Recap of Modular Character

Modular characters are made up of multiple components, which can be individually changed.

In this particular project, I am using n-hance humans. You can find that each component is available for me to modify in the character blueprint.

Modular character which allows modification of each component

This means that my inventory and item system should be able to handle modifications of these skeletal meshes as well as the material changes required.

Creating base item blueprints

As described in the previous post, I created a structure of BPs which refactor code so that I don’t have to repeat it.

Base armor item blueprints

In this case, I created a sub class for each of my equippable items for the set, this included:

  • ItemBase
    • Armor base
      • Belt Base
      • Boots Base
      • Cape Base
      • Chest Base
      • Gloves Base
      • Helmet Base
      • Legs Base
      • Shoulder Base

The armour base class is able to handle the equip functionality.

All of these items will require to specify the slotsTo parameter.

ArmourBase definition with SlotsTo variable

The RaceGender key is a simple struct containing race and gender params.

You can also just have a string with race + gender appended which would work well.

The SlotsToMeshMaterial struct is:

As you can see, its another map with key of string to value of mesh material, which is defined with:

mesh and material

The key is the skeletal mesh itself and the value is a map of material instances. This is because skeletal meshes can have multiple materials associated to them.

Equip or use function

Items can be equipped or used. As we’re in our armour base subclass, it can be equipped.

Equip or use - get slots to meshes

The first thing we need to know is which character components need updating with what meshes. This is what we evaluate through GetSlotsToMeshes function.

Get slots to meshes

This function takes our assigned character and gets the gender + race values. From this we can use it as the key to SlotsTo which we checked in the previous heading.

Now we have the Slots To Mesh Materials.

The slots is another custom term here, it refers to the component tags that I assigned to character components.

Adding custom tags in my character component

As you can see, I added custom tags to each of the character components. For example, the Boots component contains the tag ‘boots’.

This allows me to find these components as I require through my functions.

Update the character component skeletal mesh

Let’s go back to Equip Or Use Function, here’s the next part of it:

Equip or Use - update the skeletal mesh

We got the Slots To Mesh Materials and as I mentioned, this contains the slot name, which is the tag name for the component.

We therefore search our character (item owner) for this component, using Get Components By Tag. This should only return 1 component in my design as each tag is unique.

We update the skeletal mesh using the value from Slots To Mesh Materials. Specifically the skeletal mesh part.

We now need to update the materials for this skeletal mesh.

Update materials for the skeletal mesh

The key in the Material Instance parameter refers to material name, so I can simply do Set Material By Name and update all of them

That’s all the functionality we need for the equip and it can all be handled by the base subclass. Let’s explore how we un-equip items.

Un equip items

The armour base class does not have enough information to un-equip and item.

So we don’t specify any logic here for now.

We don’t need to specify the logic in each Item instance though, we can define the logic in the category classes. For example, let’s check a Belt Base class.

Un-equip belt by nulling mesh

In this case, the belt component, sits on top of the character other components. When this item is un-equipped, we can simply null out the skeletal mesh for this component.

Let’s look at more complex examples, let’s take gloves.

Un-equip gloves on character mesh

Gloves affect more than 1 component. When they’re un-equipped, I want to remove the bracerAdd component, which sits on top of characters hands. But the gloves also (potentially) modified the hands mesh – therefore I get my character blueprint to resolve this skeletal mesh and material again, based on the character base properties (like gender, race, skin color, etc).

You can do even more interesting things in these base classes, I gave the example of the helmet in the previous post, but here it is again.

Equip Helmet function:

Helmet can remove character hair and facial features
How we hide hair using helmet

When the helmet is equipped, the helmet sub-class introduces new variables for options to remove hair and facial hair. You can see that alongside the armour base functionality, you can enhance it using these sub-classes.

Then on helmet un-equip, you can revert these changes:

Helmet base - handle un equip item

This allows you to take full control of your character appearance on item equips. The key is that we refactor all the logic so that the item instances can stay code-free.

Defining item instances

I created a folder which will contain all the item sets in future, split by category.

Let’s see with first example, a Footmans Belt, which is one of the simpler examples.

There are 4 elements, one for each combination of race/gender. i.e. i have 2 races and 2 genders at the moment and will look to introduce more in future.

The expanded sample is for human male, where I define the component for belt, to be assigned the human variant of belt skeletal mesh and the associated material name.

The skeletal mesh is currently used as the dropped item skeletal mesh visual, but I will also experiment with another one (not in use yet) Dropped Item Skeletal Mesh, which I may make a small chest or something. Icon is used to represent the item in the inventory.

Item owner and Item Instance ID get populated when item is created or assigned to character.

More complex example, gloves

Glove example affecting 3 components

Gloves are able to affect multiple components at once, in my case 3 components:

  • Bracers
  • Bracers Add
  • Hands

You can see these components in the character BP:

Highlight the affected gloves components

Potentially you would have 2 separate items for gloves and bracers. I noticed my inventory icons only contained the gloves, so that’s main reason I currently bundled them together.

Another example, Legs

Legs are similar to gloves, they can affect 2 components in my example, legs and legsAdd.

Legs example affecting 2 components

I want to highlight that the assignment is repeated for all race/gender variations in my case, which means I can use the same item instances for all my races and genders

Results

I am now able to create items in my game, pick them up and equip them.

This works across both races and genders.

Equipped items results

This is the first milestone for creating item equip sets.