How To Collect Coins In Unreal Engine 5 Using Blueprints

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome to another video hello here and in this tutorial I'll cover how to make a simple blueprint setup which allows us to collect coins from our level it also counts the coins we pick up and displays it on our screen it's a very straightforward and simple thing to do and it's a good exercise for beginners so let's Jump Right In and get started [Music] the logs if you're going to create has three parts the first one is telling the engine that Every Time We Touch a coin in the 11th it should disappear so it looks like we have picked it up then we need to count the coins we have collided with and in the last part we want to show the numbers on our screen so let's start with the first part and make the Collision logic I have downloaded the coin from sketchfab to use in my project you can use your own models or you can just go with a simple cylinder that would also be fine for the purpose of this tutorial alright now let's make your blueprint select actor name it coin and open it up here in my components tab I am gonna hit add and select static mesh now just select it and here in the details tab you can add your static mesh to your blueprint foreign adjust it if it's needed and then add the Box condition to the blueprint this is the area that's where our character steps in our codes get caught so let's make it a little bigger than the coin and we are good to go here in the details tab you can see these events which enable us to use the Box Collision as we wish there are a lot of ways to work with it and the one we want to use is on components begin overlap you go to the events graph and you can see that it has made the event slot for you you can also do the same thing by clicking on this box here and selecting the event note you are looking for okay now when our character enters the Box the code we make here will be caught for example let's add sound 2D to play a sound whenever we collect the coin and after that let's add the destroy actor function to get rid of the point immediately hearing the sound function you can add the sound you want I have downloaded the coin sound effect and here I'm gonna drag it into the play sound function the thing here is that the format of the audio should be valve you cannot use other formats here so if your sound has a different format just use an online converter and convert the format to valve to be able to use it scenario alright what is going to happen here is that when our character hits this Collision box in the blueprint it will play the sound effect and after that it will destroy the coin let's component drag the blueprints into the level and see what we have got so far [Music] here as you can see it's working perfectly and we are ready to go to the next stage before we continue let's make the coins rotate around themselves to make them look cooler to do so just go to the blueprint and here in the components tab add a rotating movement here you can Define the rotation rate but in our case the default values work just smart so let's compile and play the game and now we have the rotation which make our coins look better now we can go to the next part what we need here is a counting system we want to know how many coins we have collected the first thing we need here is an integer variable to assorted data as a whole number I'm going to open my third person character blueprint and make a new variable name it how many coins and then put it on your teacher the reason I'm not making the variable in the coin blueprint is that when we hit our coins they will be destroyed so they cannot have an impact on our logic after they are gone so I'm using my third person blueprint to have my coin variables separated from the coin bullet box this video can keep the count of the coins even after they are destroyed in the level okay now let's put it on zero and go back to the coin blueprint I'm gonna move the play sound and Destroy actor functions away so I have place for my counting functions and when the counting is done I'm gonna connect them back to the chain of events okay since fee made the variable in the third person character blueprint and here we are working in the coin blueprint we need a way to make a bridge between them so they can communicate with each other the way to do that is just to add the cast to BP third person character or not this way we get access to the variables in the third person character blueprint you only have one variable here called how many coins so in my current blueprint I'm gonna drag you away from this output here and type get how many coins here it is and now you can see that I have it in my blueprint and I can work with it here okay now what I want to do with the number is that every time we hit a coin we're gonna add one unit to it and then set it again so here I'm gonna drag a wire and type add and here at the value I want which in our case is one then I want to set the variable again so I'm gonna drag it wire and this time type set how many coins and then give it to the new value for the targeting the set function we just need to connect it to usbp third person character and also here for the object just connect it to the other actor output node and you are good to go in order to be able to see what is happening I'm gonna add the print string function and connect the point variable to it so it types the number of the coins on my screen every time I connect the coin in my level before we start the game Let's increase the duration so it lasts longer on the screen and now let's count point and play the game thank you as you can see everything is working perfectly and now we are ready to go to the final part and make a simple UI for what we have created the pre-testine function is used for developing stages and you don't want to have it in your final products so we need to make a UI on our screen and show the number of the coins properly in order to do so we need a widget blueprint right click in your content browser and here in the user interface section select widget blueprint let's name it coin widget and open it up here in the widget blueprint we are able to design our UI as we like and then connect it to our other Blueprints and logic we have made in our project the first thing we need here is a canvas to frame art items properly so here in the palette type canvas and add it to the widget then we want the text so just drag it into the canvas and place it very very large I'm gonna put it here on the top right corner of my canvas and then anchor it to the corner so it doesn't get messed up when we put it on our screen here you have access to the settings of the text and you can play with these parameters to achieve what you want I'm gonna change the text to coins and then I'm gonna add just the size to make it look better in the game next I'm gonna add another text and put it right in front of the other one this is going to be the number of the coins I collecting the game so let's put it on 0 by default and then anchor it to the corner like the previous text we made thank you in order to make this UI appear on our screen we need to do one more thing I'm gonna go to my third person character and tell the engine that I want to call the wizard blueprint and show it on the screen if you need that event begin place so it runs the code as soon as we open the game then we need create a widget and after that we need an add to the import function you always need these two guys here to put our UI on our screen for the last part here I'm gonna select the coin widget which is the widget blueprint I made earlier and then connect the return value to the Target pin in the add to viewport function here and after I compile and play the game we can see the UI on our screen but here when I start collecting coins you can see that the number does not change and it's obviously because we have not connected to the coin variable we made and it's just a simple text without any logic behind it in order to connect this text to the coin variable just go back to the blueprint and select the text then in the details tab you can see a binding option this way you can bind the value to your variables and the text will get updated in the game based on the changes happening to the variable so hit create binding and here we can connect it to the coin variables we made in our third person character blueprint let's cast to third person character so we can talk to it and have access to the variable the variable is called how many coins so just drag and line from as BP first person character and then type it how many coins and here you can find it just add it to the blueprint and then connect it to the return node our variable here is an integer but the variable in the return node needs to be a text so here Aria is converting the integer to a text and then giving it to the return node also before we compile we need a get player character for the objects in the casting node and now we are good to go let's confide and play the game and yeah as you can see everything is working perfectly and we were able to make a coin collecting system with a couple of simple blueprints we also don't see the printer string anymore so let's go to the coin blueprint and delete the print string function [Music] yeah that's it for this tutorial and if you enjoyed the video don't forget to leave a thumbs up and subscribe to the channel thank you guys for watching see you in the next one foreign
Info
Channel: Unreal ART With Alireza
Views: 7,312
Rating: undefined out of 5
Keywords: unreal engine, ue4, unreal engine 4, unreal engine 5, unreal engine 5 tutorial, unreal engine 5 tutorial beginners, tutorial unreal 5, tutorial ue5, how to use unreal engine 5, learn unreal engine free, download unreal engine 5, level design unreal engine 5, level design ue5, materials in unreal engine 5, blueprints, collect coins, coins, widgetblueprint, widgets, casting
Id: VmrlmWiq9Og
Channel Id: undefined
Length: 10min 29sec (629 seconds)
Published: Tue Apr 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.