Creating Wepons Array

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 ^^