When playing Action RPG (ARPG), the player is awarded with one Soul per enemy that is vanquished. The player can then use the Souls they have collected to purchase potions and weapons in the store. While this system works exactly as it should, getting one Soul per vanquished enemy makes progressing feel like a chore instead of something that is fun. In the following How-To, we will take a look at setting up our enemies so that when they are vanquished by a player a random amount of Souls will be awarded.
Steps:
The latest version of Action RPG will already have the following setup up and working.
-
First, in the Content Browser, locate the BP_EnemyCharacter Blueprint and double - click on it to open it up.
Click for full image.
-
Once the BP_EnemyCharacter Blueprint is open, click on the Plus Sign (+) button in the Functions list to add a new function and name it SpawnLoot.
-
Select the SpawnLoot node in the graph and in the Details panel, under Inputs section, add a new Integer input named Quantity.
-
Add the following nodes to the graph. These nodes will allow us to spawn a random amount of souls in a random location with in a box.
Blueprint Node Name Default Value For Loop N/A Get Actor Location N/A Random Point in Bounding Box Box Extent X: 40, Box Extent Y: 40, Box Extent Z: 40 Spawn Actor From Class N/A -
Click on the Select Class input on the Spawn Actor From Class node and from the displayed list, search for and select the BP_SoulItem Blueprint. Blah
-
Next, connect the Return Value of the GetActorLocation node to the Origin input on the Random Point in Bounding Box node. This will make sure that when the souls are spawned, they are not all spawned on top of one another.
-
Connect the output of the For Loop, LoopBody, to the input on the SpawnActor node and the connect the Return Value output on the Random Point in Bounding Box node to the Spawn Transform input on the SpawnActor node.
-
To finish up this function, connect the Output of the SpawnLoot node to the input on the ForLoop node and then connect the Quantity output on the SpawnLoot node to the Last Index input on the ForLoop node. When all of this has been completed, your Blueprint should look like the following image.
Click for full image.
-
Now, go to the Event Graph and locate the EventDestroyed event.
-
Go to the end of the EventDestroyed and add the following nodes to the Event Graph:
Node Type Node Name Default Value Instance Editable Integer SoulMIN 1 Yes Integer SoulMAX 1 Yes Spawn Loot N/A N/A N/A To make the SoulMIN and SoulMAX Instance Editable, go to the Variables panel and click on the eye icon next to the variable name.
-
With the above nodes, we are now going to set them up so that when a player vanquishes an enemy, a random amount of Souls between the SoulMIN and SoulMAX will be spawned in the level. To get this working, set up the node to match the following image.
-
Once the random amount of Souls per kill has been set up, connect the output of the Set Collision Object Type to the input on the Add Souls node like in the image below.
Click for full image.
Don’t forget to reconnect the “Parent: Destroyed” node after our new logic.
-
With that completed, press the Compile and Save buttons and then close down the BP_EnemyCharacter Blueprint and open the NPC_GoblinBP_Level_01 Blueprint.
-
With the NPC_GoblinBP_Level_01 Blueprint open, go to the Details panel and under the Default section, look for the SoulMIN and SoulMAX inputs.
-
With the SoulMIN and SoulMAX inputs located, input a value of 1.0 in SoulMIN and a value of 3.0 in SoulMAX.
-
Now open up the rest of the NPC Goblin Blueprints and input the following SoulMIN and SoulMAX numbers. When that is completed, make sure that you Compile and Save each Blueprint.
Blueprint Name SoulMIN SoulMAX NPC Goblin Level 01 01 03 Goblin NPC Level 02 03 05 NPC Goblin Level 03 05 10 What we are doing above is setting up our Goblins NPC's to award different amount of souls based on the level the NPC is. A Level 01 Goblin awards the smallest amount of souls while a level 03 Goblin awards the most amount of souls.
End Result:
Now when you launch ARPG, the player will now receive a random amount of souls for each of the enemies that you vanquish like in the following video.