Here is how I made it:
I made the weapon1 then got the weapon2. I then made an integer to bound it, then I made a branch to see if the integer is higher or lower than a set amount, and then I made it set weapon1 to invisible and weapon 2 to visible. Can anyone tell me if there is a better way to do this?
Also interested in this. Are you using static meshes or skeletal meshes for weapons?
You should enable/disable collision if you have.
I assume that your weapons have different behaviours.
For mouse and keyboard input, you usually want to cycle with the keys ‘1’, ‘2’ … and the mouse wheel.
So having a function that swaps to the weapon with the selected ID is the right way to go. (I wouldnt store the current weapon as int though but rather as “CurrentSelectedWeapon → WeaponBaseClass” so that you can access its individual functionality.
If your weapons all handle the same way you dont need multiple meshes at the same time and have one being invisible. You can just change your weapon and your collision mesh.
If they are more complex and consist of different objects I would spawn them as individual actors and attach them.
And then you can make them visible / invisible on demand. With this solution you need to keep track of all weapons though. By storing them inside the player in a List or something. You can then use the Lists Index as the ID to switch to.
I recently had a breakthrough in this subject. Use an Enumeration, and if you’re not sure what that is, there are a few tutorials on YouTube on that. But with an enumeration blueprint you can have a set of numbers and you can name each one. ( for example you have three weapons; sword, knife, staff)
Each name will be a number. Using a switch on enumeration node, the input will follow the current number of the enum. Having it set up this way you can use the weapon matching the number. And to switch them you can just set the current enum name.
Presses |e| current enum is “sword”- output goes to sword attack
Sets enum to “staff” next |e| input executes staff attack.
Hope that helps. If it’s confusing look up enumerations in ue.