Download

A few questions on creating a weapon pickup system

Hello,

I’m trying to create a weapon pickup system that behaves similar to Call of Duty or Halo, where you stand near a weapon on the ground and you see a prompt on the screen. You hold down your interact key and it picks up the weapon. When you already have two weapons, it replaces the currently equipped weapon.

I’ve got a system already partially set up, but I’m not sure if I am on the right track. In my parent weapon class, I have a collision sphere that is tied to OnComponentBeginOverlap and OnComponentEndOverlap events, which modifies an array within the Character Blueprint. A custom event is also called to within the Character Blueprint to spawn and remove a UMG widget. Below is my Blueprint:

This seems to be the best way to do this, as it allows two or more players to stand within proximity of the weapon and be able to interact with it. Obviously when two players try to pick up the weapon at the same time, the server would only allow the first player to pick up the weapon.

Below is the custom event within the Character Blueprint:

NearInteractableActors is a macro that simply returns false if the InteractableActors array is empty. With the code above, the UMG widget appears and disappears from the screen for all players in the game when one player overlaps a weapon. I guess this is because a Character actor exists for each player in the game. By adding an IsLocallyControlled check into the execution chain, it behaves as expected, but I’m getting an The widget ‘WBP_Interact_C’ was already added to the screen. warning and I’m not sure why.

Am I on the right track here with this method?

Hard to see the blueprint on my phone but, you get that message since the overlap is probably firing off a few times.

You may want to promote the umg to a variable. So when it adds it you can use the reference before it adds it to check if is valid, if not create it and add to view port, if it is valid check if it’s on view port, if so do nothing if not add it to view port.

Finally on end overlap check if it’s valid if so remove from parent

Yup, I did try that with no luck. :frowning: