Hi there,
im currently working on a modular weapon system for my game. I have finished the setup for a first working prototype and i think i can share my results with you.
I hope some of you find it useful in some way. If you find a mistake and or design flaws please tell me i have still much to learn :).
Because of this please be aware this is just a “working prototype”. Its one of many approaches and certainly not the best. Feel free to share your comment.
The game itself is planned to be a small probably a first or third person shooter with some coop elements if i can get network working. The current state has no network functionality.
Since im quite new to sharing my stuff i hope its okay that i just post commented screenshots of my blueprints and that my texts are sometimes complicated to read :).
But i will try to answere questions.
Current Content:
- Spawn Default Weapon in FPS Hands
- Shot Projectile at Aiming Point
- Simple Ammo Drain
- Show Ammo on Weapon Mesh
- Different Trigger Types:
- Single
- Burst
- Double
- Auto
- Charge
- and hopefully more to come
So let’s get started:
My Testsetup is just the Blueprint First Person Template with Starter Content. Nothing else is needed.
- Required Objects:
- Blueprint Interface “iEquipmentInteraction”
- Actor “WeaponBase” -> Add Custom Event “TriggerImpulse” with float Input “Impulse Modifier”
- Actor Component “TC_Master” -> Add two empty functions “PullTrigger” and “ReleaseTrigger”
We will fill them with content now
- Interaction Interface - To handle the Input communication between player and equipped weapon
- Interface is named “iEquipmentInteraction”
- i added one function “Switch on off” which will tell if the trigger is pulled or released
- Adjusting the FirstPersonCharacter BP
-
add 3 new variables:
- “Nulltransform” type Transform with empty content - we will spawn our weapon here and immediatelly attach it to the Hands
- “WeaponInUse” type reference to WeaponBase" - reference to our spawned and currently used weapon
- “Aimpoint” type Vector - Position we want to shoot at
-
delete the current weapon skeletal mesh - we will spawn our own using the same model
-
Update Aimpoint every tick:
-
Spawn our weapon blueprint and attach it to the existing socket “GripPoint” on Mesh2P
-
Interact with weapon - “InputAction Activate_Primary” is mapped to my left mouse button
-
My player components and variables now look like this:
- Create Weapon Base Blueprint - our Demoweapon
-
Open Actor “WeaponBase”
-
Add skeletal mesh as root and select “SK_FPGun” - name it “VisualMesh”
-
Add Text Render Component as child of the mesh and name it “Display”
- Adjust its details:
- Location Z: 21
- Rotation Yaw: -90
- Horizontal and Vertical Alignment: Center
- World Size: 2
- Adjust its details:
-
It should now look a bit like this (you don’t have the marked components yet and my text is already updated to the current amount of ammo):
-
Next step is to add 2 new functions and 3 variables:
-
“CurrentAmmoCount” - Integer with default value 100
-
“Wielder” - Reference to “First Person Character”
-
“ActiveTrigger” - Reference to actor component “TC_Master”
-
Function “Update Display” - this will update the ammo display on the weapon
-
Function “GetPlayerAimInformation” (Pure) - This will give us the spawn transform for our projectile
-
-
My construction script now looks like this (you dont have the marked components yet)
-
And this is the “final” Event Graph for now
- Create Trigger Components - Different Components for each trigger type
-
open “TC_Master” and ad 2 variables:
- “ShotDelay” - float with default value 0.2
- “ToOwner” - reference to “Weapon Base”
-
we also need two 2 more functions:
- empty function “ImpulseFinished”
- and “InitiateTriggerImpulse” wich looks like this
-
the event graph will then look like this:
Now we can finally the different trigger types - each is a child of “TC_Master”:
Some require a few additional variables and one custom event but it should be clear with the screenshot
SemiAuto - One Shot per klick with minimum delay
SemiBurst - X consecutive Shots per mouse click
FullAuto - Shoot while Trigger is pulled
Double - Shoot when Trigger is pulled and released with minimum delay
Charge - Charge while trigger is held and fire on release
After all that is done you just have to add the trigger component(s) you want to the weapon and set “Active Trigger”.
You can also implement functionality to cycle through different trigger types with that.
We are done for now. Took me longer than expected :).
My personal next steps are:
- implement spread for projectile and trace
- multishot for shotguns
- lockon system for rockets
- windup weapons
Regards Abarudra