best way to equipp/switch weapons?
Hello, so I am currently working on a FPS game and I (currently) have 14 primary weapons and lots of attachments.
What I currently have:
When I selcet a weapon the selected weapon is attached to the right hand of my character, the same is true for the secondary weapon and the pistol. Default the secondary and the pistol are not visible and can't shoot. When I press "2" the secondary weapon is set visible and the other two guns are invisible, when presssing "1" "3" similar things happen...So the weapon switching is based on visibility.
It worked quit well, but now I am trying to add attachments to my weapons. They are only set visible inside the BP. when a player has selected them, however this causes some problems when switching weapons, as you can imagin...As there are about 30 different attachments that can be equipped(laser,scope,barrle,stock,mag...) to every weapon, setting the visibility with branches and variables seems a bit too much work. Also destroying and spawning a new gun when switching weapons is not an option, because the ammo details would get lost :/
I would like to set the visibility of the weapon and the selected attachments to visible on spawning and then when pressing 1/2/3 on the keyboard not changing visibility, but instead socets. So when spawning my visible primary would be in my hand, the secondary on my back and the pistol close to my hip.
Do you have better ideas or maybe know how to do this? Thank you very much in advance! (i know the screenshot provided is not very good...)
asked Feb 16 '19 at 10:04 AM in Using UE4
So what is the issue? Seems like a perfectly good solution to me haha Use the "attach to socket" node and when you hit 1,2,3 switch the weapons that are located at the particular sockets. All your weapons, and attachments should be visible at all times. Unless you don't want the weapon to be visible that is not active for performance reasons then I suggest having its data stored in an inventory or a simple variable within your player character that will keep track of the weapon/s you are carrying. Each weapon BP should be responsible for keeping track of the attachments/ammo it has as well. I wouldn't mess with visibility in general it is not necessary. As for the issue about losing "ammo" data for why you can't spawn and destroy weapons, it is a simple fix. You store the weapon data before destroying the weapon. Variables are your friend. Then when you respawn the weapon, provide it with the appropriate ammo count based on the stored variable.
answered Feb 16 '19 at 01:44 PM
Nebula Games Inc
Follow this question
Once you sign in you will be able to subscribe for any updates here