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

Crouch with Confidence – Unreal Engine 5 tutorial

Why?

The crouch. One of humanity’s most basic movements. Humans have been crouching since they figured out that going under things doesn’t always require us to crawl. Sometimes in games we need to duck under objects or sneak past enemies so this mechanic can be very versatile and we can build many different game mechanics into it as an example some of these could be to improve accuracy when shooting / Snipping, to reduce the characters detection rate when sneaking some games have even used crouching jump combination to reach higher platforms. All in all it can be a very useful thing to have in your game.

Resources

Provided Crouching Animations converted from Mixamo

How?
Action map and blueprint

Since 5.3.1 released we do action mapping a little bit different, no long are we going into your project settings and mapping from there. Now we are adding an Input action and adding that to a IMC (you can have multiple of these)

Now we are going to create a new input. Navigate to Content>Thirdperson>input>Actions. Right click and go to input and select input action and name it IA_Crouch. Once created open it and leave all the options as default and click save and close it.

Now we need to add it to our input mapping context, should be in the previous folder. Its call IMC_Default, open this up so we can add our mapping.

Use the plus button and from the drop down select our IA we just created and bind it to the Left CTRL key and make sure you save.

For our next step we are going to open our character Blue print (ThirdpersonBP) and setup the blue print for crouching.

Left click and search and add the action map we just created IA_Crouch and click on its expand arrow. Drag from the Started pin and search for and add the crouch function. From the completed pin add Un Crouched.

Select the Character Movement in the components tab on the top left and search for crouch.

Here we are going to click on the option at the bottom called can crouch.

We can also change our crouch speed as well as our height. The height options changes our collision capsule so we can fit under objects or landscaping you can change this if you wish. This wont make your actor animate into a crouch yet it will just reduce the size of the collision capsule. If you decide to test it at this point all you will see is the camera move. (You can also make the collision capsule Visible to test also)

Another thing that you can do at this point is that If you feel the camera movement isn’t smooth enough you are able to enable camera lag. What this will do is smooth-en the camera movement when you toggle the crouch. In order to do this select camera boom in the components tab then search for lag in the details tab and enable camera lag

Animation configuration.

Next we are going to setup the animation, we need to import the animations that are compressed in the CrouchAnim.zip file. You can click and drag or add them how you see fit. Create a folder under content call it Animation (Can add a subfolder if you wish) and add them here. You will be prompted with a FBX import options, target the SK_Mannequin skeleton and import all. Once done you should see all Five animations imported. (We are only going to use two for now, however having the others there will be good for future use)

Before we setup the blend space we need to modify the CrouchedWalking Animation to stop it repeating so open it up and on the left under asset Details we are going to enable two options EnableRootMotion and Force Root Lock

Now we are going to setup our animation blend space. To do so right click in your animations folder and goto Animations>Legacy>Blendspace 1D and select the sk_manequin and call it ABS_Crouch

Open up ABS_Crouch and Under the Asset details tab find the horizontal axis and change the name to Speed and set the Maximum Axis Value to the speed you set in the blueprint. Default is 300. Also change your grid divisions to 2 and select snap to grid.

Now on the right under asset browser find your crouch idle and drag it to the left side of the time line and then find your Crouchedwalking and drag it to the right side of the timeline.

If you hold Left CTRL and move your mouse over the time line the animation should play.

Save and Exit.

Configuring the AnimGraph in the character BP

In the content browser navigate to Content>Characters>manneqiuns>Animations and select the ABP_Manny. (this also works with custom characters.)

Find the Sequence node in the middle of the current screen and select add pin, next either get the movement component or copy and paste it from one of the existing one’s on the screen. Drag from the pin on the new movement node and add is crouching. Right click the return value and promote it to a variable and call it isCrouching? Now connect the Set to the new pin you created earlier.

Now goto the eventgraph tab in the top middle and when it is open access the AnimGraph this should be a tab in the middle top section of the screen and open up the locomotion state machine. You should see something like this

Create a new state machine and call it Crouched drag off the pin and create a new Cache pose and call it crouched.

Open the Crouched State machine and add a new state from the entry and call it crouched locomotion.

Open Crouched locomotion and add in our ABS_Crouch animation from the asset browser to the right and connect it to the result. Then from the speed pin drag it out and get ground speed.

Go back to the main AnimGraph page and open up Main States State machine. Add a new state and call it Crouched Locomotion and connect it to locomotion and back (this can be tricky at first, try dragging from the border)

Click on the locomotion to crouched locomotion. Add the variable isCrouching? And connected it to the result.

Now do the same for Crouched locomotion to Locomotion, add the variable isCrouching? From the pin drag it out and add a NOT bool and connect it all to the result.

Open up crouched locomotion now by double clicking now add our cached pose (Crouched) to the result

Compile and save.

Conclusion

You have now created a crouch input action and designed an animation blend space to facilitate crouching. This means you can now duck under low objects and hide behind cover like a true stealth master. Well done!

This versatile mechanic opens up a world of possibilities, from enhancing shooting accuracy to reducing detection rates. How you choose to implement and balance these pros and cons is up to you. Happy crouching!

Walk This Way – A Unreal Engine 5 Tutorial

Welcome

Welcome, adventurers, to the first of many epic Unreal Engine 5 tutorials! When I first ventured into the vast realms of UE5, I was met with a labyrinth of confusion and intimidation. Though countless YouTube tutorials offered guidance, the seasoned explorers crafting them often moved at a pace that left novices like myself struggling to keep up.

But fear not, brave traveler! Enter my enchanted tutorial series, where written guidance shines like a beacon in the darkness. Here, you can progress at your own pace, and with the aid of detailed screenshots, each step of the journey becomes clearer and more manageable.

In this inaugural tutorial, we shall embark on a quest to master the basic yet essential art of character movement. Our first mission: to implement a walk mechanic. This spellbinding process can be woven into any UE5 template featuring a controllable character.

So, gather your courage and your creativity, and let us begin this wondrous journey together!

Why do we need to walk?

When we play a game we are not always running everywhere and we are also not walking everywhere. With the default presents in UE5 regardless if its FPS, 3rd person or top down. The max movement speed is the same. We can change this by creating a blueprint that is toggled by a key. When we do this the 2d blend space takes over and slows the animation or speeds it up depending on the way we go.

The Process

Start a new project or open an existing one that has a player actor blueprint for this tutorial we are going to use the thirdperson template. When you are in the engine we are going to setup a new action. Doing this will later on allow us to customize the key binding for our walk / run function allowing your player to customize what key binding they are going to use for it.

This has now been replaced by using the Input action and input mapping context system (look below for the updated procedure)
To do this we are going to go to settings and search for action mapping. We will add a new action mapping using the plus button and call in Walk/Run Toggle and for now bind Caps lock to it.

Action map and blueprint

Since 5.3.1 released we do action mapping a little bit different, no long are we going into your project settings and mapping from there. Now we are adding an Input action and adding that to a IMC (you can have multiple of these)

Now we are going to create a new input. Navigate to Content>Thirdperson>input>Actions. Right click and go to input and select input action and name it IA_Walk/Run Toggle. Once created open it and leave all the options as default and click save and close it.

Now we need to add it to our input mapping context, should be in the previous folder. Its call IMC_Default, open this up so we can add our mapping.

Use the plus button and from the drop down select our IA we just created and bind it to the Capslock key as shown in the first screenshot and make sure you save.

Next we are going to find and access our character blueprint, depending on the preset you selected the name is going to be different for this example we are using the 3rd person preset so find BP_ThirdPersonCharacter and navigate to the event Graph tab. Click in a space to add a new node and search for our action event “Walk/Run Toggle” and add it.

Instead of inputaction it will now show as enhancedinputAction IA_Walk/run toggle

Just to reiterate, doing it this way allows your player base to customize what key they use when your game is released.

Next lets take a look at how we can create our blueprint to alternate our walk/run speed. We could do this with a flipflop however by learning the more complicated way of doing it will give us a few more options later on. So lets do this with a branch or a ELSE IF.

Firstly lets create a Boolean variable and call it “walking” compile your blueprint so we can set its default value and this is up to you however I am going to leave it unticked so our default state is running.

Once you have done this we need to now add this to our blueprint and start formulating our
branch. Click and drag your variable into your blueprint and use Get. Drag off the pin and add a branch node. The Walking variable will now be the condition of the branch. Go ahead and connect our action node “pressed” pin to the branch.

Next we are going to setup our True/False conditionals, if walking is currently true that will change our movement speed down and if its false it will increase our movement speed. So lets add the Character Movement, from the top left in our components tab click and drag Character Movement to the blue print. From its pin drag out and add Set Max Walk Speed, this will allow us to alter the speed. Connect the true pin on the branch to the set and make the speed 500 (this is the default)

Now when walking is false we need to setup what to do. Once again drag off of the character movement node already in the blue print and add another set max walk speed. Position it so it is below the first this way it makes sense when we connect our false pin to it. For the value it is upto you but lets say we set it to 120. You should now see something that looks like this

now this is complete we still need to tell the walking variable what to do, so we need to drag and set our walking variable in and connect it to our top movement set and make sure its un-ticked. Do the same thing for the bottom set and make sure walking is ticked.

So compile and save so when you now play test and press caps lock or whatever is bound to it it should alternate the speed the character moves. Ultimately the speed set is up to you and what you want for your game.

Conclusion

So now, with just a press of a button, we can seamlessly toggle between walking and running, creating a more immersive experience for players. This enhancement allows them to better appreciate and explore the stunning landscapes you’ve meticulously crafted, making every moment in your game more dynamic and engaging.

Additional

We can expand upon this by controlling the speed with variables (Float) we would ideally do this if we want items, encumbrance or even a leveling system to dictate the speed at which our characters move. Just makes it a little more easier to manipulate. So Create two new variables and name them MaxWalkSpeed and MaxRunSpeed set them as a float, compile your blueprint and then edit the default value. Once done drag and get them into your blueprint and pin them into the corresponding set nodes we added previously.

Additional 2

Now we have a complete blueprint setup for Walk/Run toggle we can turn this into a function. This basically turns all of your nodes into one. This makes for a cleaner blueprint, this also makes it reference-able and reusable in any part of our game. To do this highlight all of our nodes and right click, in the contextual menu find and click collapse to function.

It will now appear on the left-hand side under the blueprints tab and we can rename it by right clicking and selecting rename. We can rename this function WalkRunToggle.

Additional 3

If you have a crouching mechanic you can also alter the speed of this using the same process simply add in your max crouching walk speed.