Problem with several same Blueprint Actors in one level

Hello,
today i wanted to create a pickup system for Weapons in my project. I created a Weapon blueprint(Actor) and an Inventory blueprint(Actor) with some functions.
My idea was:




The Actor will be attached to a Socket later. Setting the Actor hidden in Game is just for testing.
Everything works fine but if i place more than one Weapon in the Level it hides everytime the first Weapon i placed.
I don’t know how to solve this problem because i’m new to ue4 and blueprint as well.
I hope somebody can help me with this.
Greetings,
El0dryn

You’re getting all actors of a class, and then getting index 0 from that array.

GetAllActorsOfClass, as its name suggests, will return an array (a group) of all the actors of that class. Index 0 is the first slot in that group, aka the first weapon you placed, so the behaviour you’re seeing is normal.

Using GetAllActors for your Inventory reference is ok assuming you only ever have one, but for the rest you should:

  1. Pass a “Reference To Self” into your Check Pickup function. Create a new Input in your Check Pickup function, of the type of your weapon.
  2. Inside Check Pickup, pass that reference again to your Pickup Weapon function.
  3. Inside Pickup Weapon, use that reference as an input for Set Actor Hidden, and get rid of the GetAllActorsOfClass/Get nodes.

That’s how to fix the setup as you have it in your screenshots, however there is a much simpler way to do all of this.

In both cases (Pickup Ammo or Pickup Weapon), you want to hide or destroy the weapon, so there’s no point in having your inventory tell your weapon to hide itself, you can just hide the weapon as soon as you pick it up.

Just get rid of the GetAllActors/Get nodes in your Pickup functions, and put the Set Actor Hidden (or Destroy Actor) node directly after Check Pickup, in the Weapon blueprint.