Weapon Switching - Referencing the Current Weapon

I’m new to UE4 an have been following along with the excellent TwinStickShooter tutorials from the Epic Games team on YouTube. I’ve hit a bit of a snag in terms of weapon pickups and editing variables.


Goal: Weapon Pickup replaces current weapon.

Problem: Weapon Pickup cannot modify ‘CurrentWeapon’ variable used to drive shooting functions


Weapon is spawned on begin play and set as a variable, ‘CurrentWeapon’. This variable drives shooting events by triggering Fire events on the weapon.


When triggered by a pickup, WeaponBlueLaser (created as a child of the original weapon blueprint) spawns an actor of the same name, destroys the old actor and attempts to set the ‘CurrentWeapon’ variable to accurately refer to the new weapon. However, it is not possible to set this to be the new value of ‘CurrentWeapon’.


I guess my questions are:

  1. Can you change the value of a variable referring to an actor, or is there a method of clearing the value to store a new one in the same variable?
  2. Is it possible to call custom events of identical names on whatever the attached actor is, without defining specific “IF Weapon 1, Fire Weapon 1, IF weapon 2, Fire Weapon 2…” etc.

I suspect that I’m missing some very basic principles, considering how logical I feel this should work and how I can’t wrap my ahead around another way without having access to a CurrentWeapon variable that updates. Any nudges in the right direction would be very much appreciated, thanks!

It would be easier instead of using 2 or more different weapons to setup a “master weapon” that could have all the same variables etc in it and then create child versions that you could then change the values in and swapping one with another wouldn’t cause any issues because they would all derive from the same BP. So setup a MasterWeaponBP and in it setup all the logic for spawning projectiles etc and create all the variables you wish the weapons to have (such as projectile to spawn when fired), then when you pick one up the fire function is the same for all of them the only differences will be the variables (such as what the projectile fired will be or what montage to play etc). Setting up the master system makes it really easy to go make a child version that is a pistol and then changing its mesh component to a pistol mesh and its projectile spawn to “pistol projectiles” or make a rifle that spawns “rifle projectiles” or a rocket etc etc.

Thanks for this, I’ll give it a go. When you refer to making a child version, does that mean making a child actor within the MasterWeaponBP, or actually making a child BP? I’ve tried making a child BP, which I guess is because the actor name is different.

Thank you for your answer! My problem was that although I had created a child blueprint from my master blueprint, I had not set the new weapons parent class to be that of the original weapon. Because of this, I was unable to modify the ‘CurrentWeapon’ variable in my character controller functions.

Once the new weapon’s parent class was set up correctly, everything worked as planned. Thanks!