sexta-feira, 2 de abril de 2021

PlayerCharacter: Blueprint adjustments

In this article we will make the necessary adjustments to the Blueprint BP_PlayerCharacter to implement the projectile change by the player.

First, let's add an Input mapping for the player to change the projectile using the Tab key.

In the Level Editor, access the Edit->Project Settings... menu and in the Engine category, choose the Input option. Click the + symbol next to Action Mappings, write the name Change Projectile for the new Action Mapping and select the Tab key:


Open the Blueprint BP_PlayerCharacter. In the Event Graph, add the InputAction Change Projectile event and the Change Projectile function that we created in C++.


In the My Blueprint tab, click on the eye icon and check the Show Inherited Variables option so that the variables we defined in the C ++ class are displayed. The variables are in the Projectile category.


Select the Array ProjectileClasses. In the Details tab, add 3 elements to the Array and select the Blueprint classes BP_PlayerProjectile1, BP_PlayerProjectile2 and BP_PlayerProjectile3. Each of these Blueprints represents a type of projectile.



In the Event Graph, InputAction Fire event, look for the SpawnActor node. Click and drag the CurrentProjectileClass variable from the MyBlueprint tab and drop it on the Class parameter of the SpawnActor node.


When the player shoots, the SpawnActor node will create an instance of the class that is stored in the CurrentProjectileClass variable.