Variables UE5

Chris Didier
2 min readMay 21, 2022

We are going to start using variables to keep track of the remaining ammo we have available to our player.

Variables help us store, manipulate and refer to information.

Each variable has to have a name, Data value, and be of a particular type.

On the left hand side of our blueprint we will look at the my blueprint tab.

Go to the variable column and click the +.

We are going to add our ammo and select the integer type which is for whole numbers. We are then going to compile our blueprint and then select ammo and we can set a starting ammo count.

We can drag in ammo to our event graph to set the starting ammo count or get the ammo count that we have already assigned.

We can use shortcuts to get the ammo using ctrl to get or alt to set.

If we want to print our ammo count to the screen we can get the ammo and print string and hook up the print string to our other print strings. Our get ammo will be converted into a string.

Now we are going to start counting down our ammo count after we fire a round. To do this we are going to get our current ammo count and subtract one from that count after we fire and then repeat until we are empty.

So every time we press left mouse and fire our count is reducing. We can keep shooting if we get to 0, but the reason for this is we haven’t added the code to stop firing yet. That will be our next tutorial.

--

--