How to implement a Score System

If you’re working on an Arcade type of game, you will need a Score System, so in this tutorial we will create one from scratch and add it to the template, this can be considered Part II of the Mobile Tutorial, but it’s also its own thing.

 

ENEMY SPAWNER

First create a new Blueprint Actor and call it “Enemy_Spawner” or something along those lines, add only a box component to it, to use as a volume for where the enemies will spawn.

After that create a new function for every type of enemy that should be spawned.

Score_EnemySpawner_Soldier
This example is for the soldier type, but others have identical logic, only the class is different.

After that, create a Custom Event and recreate this Blueprint.

score_enemyspawner_newnames

 

GAME MODE

Now let’s move on to the GameMode, create a new Int variable (Score) and add this to Begin Play. What this will do is call the Custom Event from the Enemy_Spawner and spawn a random enemy every 2 seconds.
Score_GM_BeginPlay

Now (still in GameMode) create a new function and call it AddScore, nothing too complicated, just an input integer and some basic math to 1+1 it and set the result.
Score_GM_Add

 

ENEMY

Now open any enemy and add this to its BeginPlay
Score_EnemyBeginPlay

And this to when its health reaches 0
score_enemydead_newname

 

PLAYER HUD

Now let’s move on to the HUD widget, add the GameMode reference when it’s constructed, same way like with the enemy, Character should already be there.
Score_HUD_Construct

Now add a new text and create a binding, this will display the current Score on the HUD.
Score_HUD_Text
Score_HUD_TextBinding

 

GAME OVER WIDGET

And last but not least, do pretty much the same on the GameOver widget.
Score_GameOver

gameover_new_widget

Score_GameOverGetText

 

CHARACTER

When the player health reaches 0, instead of the default respawn logic, simply create that new game over widget and add it to the viewport

gameover_new_chardied

 

RESULT

If you followed all steps from this tutorial and the mobile tutorial, this should be the result, minus the assets of course..

As you can see the enemies attack you in random patterns, score gets added everytime you kill an enemy, on game over, it shows the total score.

 

EXTRA STEPS

You can expand this system to include other things as well.

Score_GameMode_TimerTimer (GameMode), StartCounting on BeginPlay and add a text to the HUD to show it.

 

Score_EnemyDistance
Making the enemy sense the player from a huge distance, so that it actively tries to reach the player, even if there are walls separating them.

 

Score_EnemySpawnerLevel
Add the Enemy_Spawner in more than one location in the level.

 

 

NOTE: You can also download a slightly different (newer) version here. Wave Based Game Mode example, extract like it is in the zip file, open the level that comes with it, press play.

Download BP Wave Based Game Mode