Devlog 4: Elijah Jackson: I Want *That* Weapon


"I Want *That* Weapon"

Elijah Jackson

05/09/2025


Weapon Instancing:

This week, I worked on the instancing of weapons. Our game had the problem of the player only being able to have one weapon at a time with no way to swap between weapons or drop your current weapon. This presented a challenge because our game is designed to support the player having multiple weapons to fight with over the course of a session. In its current state, the player could pick up and use one weapon at a time, with their previous weapon being deleted upon picking up a new one. This is because, the weapon is attached to the player via a child actor component. In Unreal Engine a  child actor component is an actor that can be attached to the player and spawned at runtime. Whenever the class associated with the child actor is changed the attached actor is destroyed and a new one matching the weapon class is spawned. Due to the destruction and respawning of the weapon being a part of the system, I needed to find a way to cache off the data for each weapon to allow that weapon to be picked up later or swapped back to. This would also allow swapping between weapons to not reset important data such as current ammo, level, and any other weapon specific data in the future.

At first I tried to make my own custom component, but ran into similar issues as the child actor component. I needed to be able to save the data associated with a weapon even if that weapon wasn't currently in use by the player. After writing a custom component I came back to the idea of caching off the data before the weapon was deleted in order to preserve it. Technically it wasn't the *same* weapon but the newly spawned weapon would hold the exact same data as the old one. I accomplished this by defining a new struct that holds data needed for the weapon to be saved. The player holds multiple of those structs for resetting weapons allowing for changing between weapons.

Additionally, using the data from the struct when the player tries to pick up a weapon but has reached their max amount of weapons (currently we have that set to two but it will be upgradable in the future) the weapon they are holding will drop onto the floor allowing them to pick it back up if needed. The thought behind this system is that the player can try a new weapon for a moment and then pick up their weapon to continue fighting if they need to. I do plan on adding a timer to the weapon drops so they don't flood the map later in gameplay. The weapon data is setup to be easy to expand upon as needed for the weapons and utilizes class hierarchy to send the required data for each weapon. For example, the struct contains a currentAmmo parameter, but the base definition for the loading of weapon data doesn't use that parameter for anything since melee weapons don't have current ammo. This prevents having to declare ranged specific variables in the base weapon class that all weapons inherit from while still allowing current ammo to be saved by the struct. These unused variables can have their definitions made wherever they are applicable without causing any other weapons to have issues.

What's Next:
This week, setting up the weapons system and cleaning up some of the project's internals was a lot of my focus. I wanted to jump right into "finding the fun" as I wrote last week but wanted to make sure that the base we are building off of is firm and doesn't have any noticeable organizational issues. The weapon swapping feature is my large feature for this week, but on the internal side I'm still finishing up making the code easier to work with overall. Next week, I plan to add more abilities and help establish more of the gameplay loop overall. Definitely excited as we step towards a more playable build! Thank you for reading!

Get Project Meltdown

Leave a comment

Log in with itch.io to leave a comment.