How do I create a item counter mechanic when picking up an object?

blueprint help

I have set my character to pick up the items i have in my level but i’m struggling to add a counter for when i pick them up, any suggestions on how i can do this? i’m quite new to ue

One possible option would be to have a variable for the counter in your PlayerState which is accessible in your blueprint “Get Player State”

You would implement your own Player State of course where you would add the variable, and then override the default Player State in the Project Settings (or your GameMode blueprint if you are using one of those)

You could then increment that variable when you pick up and decrement that variable when the player consumes or uses or spends or whatever

Im very new to this, without asking too much is there a way you could simplify this for me. I have made a UMG widget for the item that has been collected and a number. I have the player character and the item, i just cant figure out how to connect them all together.

i need the text to change when i pickup the item, for example the counter starts on 0 and i want it to change each time i collect a new item. I’m completely stuck as you can probably tell

When you print the variable to screen, the variable IS the text, so when the variable changes, the text will change.

PlayerState is the bag for all variables (state) that you want to keep for a period of time (a level, a mission, the whole game) that relate to the main player.

You would create one by adding a new blueprint that extends PlayerState in the list of classes at the bottom of the add blueprint class dialog. You can then add variables to that blueprint class to store your values for the duration of the desired period

To make your PlayerState active you change the default playerstate class in the project settings

Then when you call get player state from any blueprint, it will be the one you have created

So in your pick up blueprint (if you had a player state variable PickupCount) you would do the following

Get PlayerState

Get PickupCount from playerstate node

Add 1 to PickupCount

Set PickupCount with result

Then when you are printing the count to the screen just do the same thing to get the PickupCount from the PlayerState


ive made it so the text appears after you pick up the item, but the text is really small and it disappears after a second. what i’m aiming for is just like the counter in this video

The print string is really just a debug tool so you can see what’s going on. If you want it to stay on the screen, you’ll want to hook it up to a tick.

If you want to create a real HUD, like in that video, it will take a lot more work. You’ll want to look at tutorials for HUDs, Widgets, and UMG.