Creating Wepons Array

Hello, everyone. I’m a little bit lost in the weapons system. So i’ve got a several types of guns and they all have a different types of shooting. Player can care only two guns and can switch them. So I don’t understand how I can create this system and where put my blueprints for shooting. I’ve got one button - LMB, but for each gun must be different option for one button. For example: when character holding automatic gun, gun must constantly spawn bullets, while you holding LMB, but when you switch to semi-automatic gun, gun must spawn one bullet when LMB pressed. So how I should create this system? Should I use some kind of Struct? Should I make blueprints for each gun? Where I need to put my shooting logic: inside the charecter or inside guns?

The answer is yes… you can do all of those things, or none of them… easiest thing to do is to create a variable on each of the guns that designates a type… automatic, semi etc… then on your LMB button down, create a switch that checks that value and either loops firing, or fires once and stops… You’ll also need variables for ammo count etc… On LMB release, you’ll need to cancel the loop if it’s running. The gun can handle its own fire type, damage etc… if you want, you’ll just want to call an action on it telling it to fire. Another trick is to create a master gun as a parent to all of these other gun blueprints… that way the fire action can live on the master parent, and you won’t need to call a specific gun to fire whatever one is selected

Thank you very much, I will try to use both variants and choose the best.

Nice coincident - I was working just yesterday on starting the implementation on a pickup-based weapon system for my GTA2-Remake^^
I don’t know whether I chose the most smart way of doing it, but maybe it might be interesting to you to have a short overview? Just in a few bullet points:

  • I have a weapon parent class (blueprint actor), that holds the weapon mesh and the required events (e.g. FIRE) and variables (e.g. ammo, maxAmmo), that will be needed for using the weapon. I then created instances for all the individual weapons (machine gun, grenade, rocket launcher) etc and modify the mesh and the actual logic that is fired by the FIRE event. In the same way, secondary options could be implemented.
  • My PlayerController has an empty array of the weapon parent, which represents the currently for the player available weapons. To the array I can easily add or remove individual instances of the child classes. Adding weapons is handled by the weapon pickups
  • Similarly to the weapon parent, I have a parent pickup class (again, blueprint actor) that holds visuals (mesh, particle effect) but also a collision sphere for detecting, if a player touched it. The parent class furthermore handles that logic in the following way:
    o Find the playerController of the pawn that touched the pickup
    o Spawn an instance of the according weapon class and attach it to the player
    o Add the spawned weapon to the weapon array of the playerController
    The last two points only occur, if the playerController’s weaponArray does not already contain an instance of the according weapon class (i.e., player does not already have this weapon). Otherwise, the ammunition will be replenished.
    Again, I create children classes of this parent pickup class for each weapon pickup-type

So far it works nicely, I can also provide you some screenshots, if you want some details, but Iam not sure, when I will have time to create them…
TODO:

  • Within the playerController: Implement function for selecting an “activeWeapon” from within the weaponsArray and tying LMB/RMB events to the according FIRE-events of the weapon.

As said, it don’t have it yet entirely finished and hope that everything works well in the end, but it looks good so far.
Are you working on a multiplayer game? If yes, you have to pay attention at a few spots to assure correct replication of everything that happens ^^