Item interaction with counter – Unreal Engine 5 tutorial

For some strange reason this post is missing some information and screenshots I will need to fix this post

Why?

In Unreal Engine 5, the ability to interact with items is a fundamental aspect of many games. One of the most common interactions is picking up items as our character moves over them. This mechanic not only enriches gameplay but also adds layers of complexity and engagement. Imagine your character collecting coins, gathering resources, or picking up key items essential for progression. By implementing item pickup and counting systems, we can create immersive and rewarding experiences for players, enhancing both the challenge and the satisfaction of the game.

The Process

If the object is a staticmesh you will need to convert it to a BP do so by adding the item into editor and then using the blueprint button convert selection to blueprint.

If the object is a staticmesh you will need to convert it to a BP do so by adding the item into editor and then using the blueprint button convert selection to blueprint.

Edit the added object blueprint from the world outliner.

Once in the editor open viewport and you will need to add a collider. (which one depends on the item)

Now rescale the collider to match the item

Next scroll down in the right menu and find events. Select on component begin overlap

In the editor cast the event to the character. If using the 3rd person template cast to ThirdPersonCharacter and add other actor from the event into the object of the cast then to show the item has been picked up connect the cast to a DestroyActor (don’t forget to compile)

Create a counter for the item

What good is an item if we do not know what we have, or how many we have picked up? Lets create a simple counter.

First open up your Character Blueprint (First person/ 3rd person/ top down)

Select viewport from the top tab and then create an overlap event from the details menu (on the right)

The event will be triggered by the coin actor with a Cast to “object name”, we will also create a Variable as an integer and call it TotalCoinItems and specify the default value will be 0. We will the Set the value by dragging off the cast and getting our variable and adding 1 and connect it to our set

To add a counter to the screen you will need to add a GUI widget and bind a text box and use the following code

Conclusion

This is how we are able to interact with items on a basic level and have a counter on the screen showing the amount of items we have picked up.

For some strange reason this post is missing some information and screenshots I will need to fix this post

Leave a Reply

Your email address will not be published. Required fields are marked *