Multiplayer TopDown Survival Kit

Dropping / picking up items isn’t implemented in the game because it’s rather unusual for TopDown games. But you can pretty quickly implement it on your own!

Here is a step by step tutorial how to drop / pick up item actors:

  1. Add a variable of type Actor class to BP_InvItem.

  2. Create the private function DropActor in BP_PlayerCharacter:

  1. Create an event that runs on server and calls the new function:

  1. Edit the OnDrop function of BP_UI_MainHUD like this:

  1. Create an actor (for example a medikit) with a static mesh for any of your inventory items and ensure it replicates. You might also want to enable SimulatePhysics for that static mesh.

DropPickupActorsTutorial_4.png

  1. Choose an item ( for example the medikit) and set the new actor class variable (created in step 1) to the newly created actor.

Now you should already be able to drop that item by drag & dropping it anywhere in the world (not on any widget).

  1. Create a new Blueprint Interface BP_IPickupable with a function that returns a variable of type BP_InvItem class:

DropPickupActorsTutorial_4.png

  1. Add the interface to the medikit and implement its function:

  1. Create the private function Pickup in BP_PlayerCharacter:

  1. Add a hotkey for picking up items under Edit->Project Settings->Input->Action Mappings. Name it Pickup for example.

  2. Create the following 2 events:

You can now drop and pick items up!

In TopDown games you might want to check if the distance between the player character and the hit actor is smaller than a specific value in the function Pickup. And additionally send a LineTrace from the player character to the hit actor in order to ensure the player can’t pick up actors behind walls. Please note that on the example map you have to choose a trace channel that isn’t blocked by the roof of the house (and it’s hidden mesh that ensures correct shadow casting) or change the collision presets of those 2 meshes.

In FirstPerson games you want to replace tracing from the camera into the cursor position by tracing from the camera into the camera direction (CameraManager->GetActorForwardVector). Because the GetActorForwardVector is normalized (has length 1.0) you want to multiply it with a float value that defines your maximum “pickup range”.