In Unreal Engine, you will probably want a way to keep a score in your game. The video above shows how. To do this, I use variables to set the score, then widgets to show the variables to the user. This video also uses casting for different blueprint classes to talk with each other.

To get started, make an Unreal Engine project (try third person character template). When it loads, right-click in the bottom content section, and press blueprint class, then press actor. This is going to be a block that gives you a point if you hit it. Open it up, and select the green button in the top left that says add a component, and pick a cube. On the bottom left, you should see some controls. Scroll down to the collision section, and then change the collision preset to OverlapAllDinamic. Open your game’s character (for me the third person character). Create a variable by pressing the + button next to the variables, and name the variable score, and set it to an integer in the top right corner. Go back to the actor we made before, and open the event graph for that (on the top middle, below the main bar) and drag off from event begin to overlap, and do cast to third-person character, or whatever your character is. Drag off from the object and pick get player character. Pull off from the as third-person character, and say set score. Do the same thing again, but this time get the score. From the get score node, type + and pick integer + integer. For the second integer, pick 1. Set that as the new score

It should look something like this. Now if you close out of this window, and go to the editor, and drag in this actor we just made, it will put your score up by one, but we will not be able to see the score. To set that up, right click in the content area, and go to user interface, and pick widget. Drag some text onto the screen, and in the right, where you would set the text that you see on screen, click the bind button. Here, you should also cast to your player, and do the get player character thing, and as your player, you want to get score, then drag that into the text.

Back in the editor, got to blueprints in the top middle, and select open level blueprint. Drag off form event begin play with create widget, and pick the widget that you just made, then do add to viewport form that, and drag the return value from the first block to the second.

Now, when you start the game, you should see the score.

© The Unreal Cousinzzz 2020

Leave a Reply

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