Adding Score
Adding Score
Double-Click on the FirstPersonGameMode blueprint. Go to Content Drawer Content > FirstPersonBP > Blueprints
If this window opens, choose Open Full Blueprint Editor
Right-Click on the work area and add Custom Event.
Rename the Event AddTargetPoints
Create a new variable. In the Blueprint editor, under the "My Blueprint" tab, press the + Variable button to add a new variable. Rename it "TargetScore". Select the new variable and under the Details tab, change the variable type to 'Integer'.
Drag the new variable to the workspace and choose Get TargetScore
Drag the output of the new varible, AddTargetPoints, to a math command Integer + Integer. Search for Add.
Hold the <CTRL> button and drag the top connection on the Math addition node to the bottom connection.
Select the AddTargetPoints node and under the Details tab press the + next to Inputs.
Rename the input and change the variable type to Integer.
Drag the new input, 'AddScorePoint' to the Math addition node to the top connection.
Drag the new variable - 'TargetScore' from the variable list to the workspace and choose Set TargetScore.
Now connect the nodes as following.
Compile and Save.
Open the Blueprint editor for the scored object. In my case I double-clicked on the Sphere_Blueprint. You may have to navigate to Content > FirstPersonBP
This is how mine looks . . .
*Yours maybe simpler . . .
From DestroyActor, drag the output and Search for Cast to FirstPersonGameMode
Drag Object Node from the Cast to FirstPersonGameMode and release. Then Search for Get Game Mode node.
It should look like this.
Drag As First Person Game Mode from the Cast To FirstPersonGameMode and connect it to Add TargetPoints.
It should look like this . . .
Right-Click on Add Score Points from the Add Target Points node and choose Promote to Variable.
This creates a new variable. Rename it Target Score and make sure it is an Integer.
Compile and Save.
After compiling, you can set the Target Score increment value. Change it to 10 points for every hit.
Compile and Save.
Right-Click on the Blueprint Content Browser and choose User Interface > Widget Blueprint
Rename the Widget Blueprint to TargetScoreHUD
Double-Click on the TargetScoreHUD icon and the HUD workspace will open up and look like this . . .
Search for canvas panel
Drag the Canvas Panel out on tpo the workspace
In the Palette Tab, search for and drag out a Horizontal Box. This is a container for the score text. Scale and move it appropriately for your score.
Drag a Text object into the Horizontal Box. With the new text object selected.
In the Details Tab, change:
The Vertical alignment to Centered.
Content:
to the desired text - Score:
Appearance:
Color of the Text?
Font Style?
Font Size. I set it to 40
Drag another Text object into the Horizontal Box next to the first text box. With the new text object selected.
In the Details Tab, change:
The Vertical alignment to Centered.
Content:
Text to the desired text - 0000000:
Appearance:
Color of the Text I changed mine to green,
For the Font attributes
Font Style?
Font Size. I set it to 40
Select the 2nd text object with the 0000000 and in the Details Tab choose Bind and select +Create Binding. MAKE SURE YOU CHOOSE THE CORRECT BIND UNDER CONTENT
The Graph Editor will open and two new nodes will be created. It should look like this.
A new Window will appear - We will cast or send the Target Score to the FirstPersonGameMode.
Select the first node ans rename the node Target Score
Drag the output of Target Score to Cast to BP_FirstPersonGameMode (Do Not cast to the FirstPersonGameMode Class)
It should look like this.
Reorganize the nodes to make room for the next step.
From the FirstPersonGameMode
It should look like this . . .
From the Cast to FirstPersonGameMode node As First Person Game Mode output, drag out and connect to Get Target Score.
It should look like this . . .
Drag the Target Score output to the Return Value of the Return Node
The ToText is automatically generated. This converts an integer to text.
Compile and Save.
Close the Graph Editor
Open the level blueprint. Blueprints > Open Level Blueprint
Change Class to TargetScoreHUD
Drag the output of the Target Score HUD Widget to Add to Viewport
It should look like this . . .
If it looks like this, it will auto correct in the next step.
Drag the Return Value of the Create Target Score HUD Widget to the Target Input of the Add to Viewport node
Compile and Save.
Double-Click on your scored object. In my case it was the cone.