5. Pick up Currency with Interaction Component {{ currentPage ? currentPage.title : "" }}

Create Interactable Actor

You have two Options:

  • Make a Child of SP8_InteractableActor_PickUpCurrency.

  • Create a new Blueprint without a Template.

I will explain both!

Make a Child of SP8_InteractableActor_PickUpCurrency

1. Create a new Blueprint and select as Class SP8_InteractableActor_PickUpCurrency.

Do not forget to set the Interaction Profile inside the Blueprint SP8_InteractableActor like descriped inside this Tutorial, if you haven’t done it yet!

2. Create a new GameplayTag and call it Interaction.Types.PickUpCurrency.

3. Open your new Blueprint and go to the Class Defaults and set your Interactable Actor Type to your new Gameplay Tag.

Create a new Blueprint without a Template

1. Follow this Tutorial.

2. Add the Interface SP8_BPI_Interaction_Currency like you added the SP8_BPI_Interaction.

3. Create a new GameplayTag and call it Interaction.Types.PickUpCurrency.

4. Edit the following Interface Functions:

  • SP8_SetCanInteract: Create a new Variable and call it canBeInteracted [Bool]. Set this Variable inside this Function. The Variable should be replicated! Also return true, if it worked!

  • SP8_CanBeInteracted: Return the Variable canBeInteracted.

  • SP8_GetInteractionType: Return the Gameplay Tag Interaction.Types.PickUpCurrency.

  • SP8_RemoveCurrencyActor: Destroy the Actor (Should be Replicated)

  • SP8_GetCurrency: Return the Currency Values, which can be picked up. Create a new Variable [Array - SP8_S_CurrencyValue] and set Instance Editable and Expose on Spawn to true. Return this Variable.

Add the Actor to your Level

1. Simply drag and drop your Blueprint into your Level.

2. Click inside the Outliner of the Level on your Blueprint and inside the Details Panel edit following:

  • Currency: Set the Currency you want to pick up.

    • CurrencyType: For example Currency.Type.Gold

    • Value: For example 10

  • Text: 10x Gold

This will display an Actor with the Title 10x Gold over it and if you pick it up, you will get 10 Gold.

Setup the Player

1. Without PlayerTemplate: You need to listen to the InteractedWithActor Dispatcher of the Interaction Component.

Inside there you need to do following:

  • First of all check if the Interaction Type is Interaction.Types.PickUpCurrency.

  • If yes, you need to Set Can Interact to false, so nobody can take it. Also check if it worked.

  • If yes, you need to check if the SP8_BPI_Interaction_Currency is implemented.

    • If no, you need to set can Interact to true.

  • If yes, you need to get the Currency inside the Actor and call Add Amount on the Currency Component for each Currency.

  • After that you can call Sp8_RemoveCurrencyActor on the Interacted Actor.

2. With PlayerTemplate: Go inside your Player BP to Class Defaults and set the Variable Interaction Type Pick Up Currency to the Gameplay Tag Interaction.Types.PickUpCurrency.

3. Listen to an Key Press, which you want to interact with this Actor.

Call InteractWithClosestActor on the Interaction Component and do following:

  • Interaction Type: Add Interaction.Types.PickUpCurrency

  • RunOnServer: Set to true, because Currency can only be added on Server.

If you move now near your Pick Up Currency Actor with your Player BP and you press (in this example) on the Key ^, you will Pick up the Actor.

Of course only if it is closer then a other Interactable Actor with one of the Types you put into this Function.

{{{ content }}}