Do I need a seperate function for each possible weapon pickup in my game, or is there an efficient way to do it?

Hello!

Quick run down of my set up before my question…

Player presses E > LineTraceByChannel looking in my custom trace channel of ‘Interactable’ > I break the hit and cast to my base Pickup class > I then cast that to the base weapon class (Pickup_Weapon) class (a child of the base pickup class) > I check a variable named “Weapon Number” set on each child of the Weapon class, so Rifle is set to 0, to match my enum ‘PlayerWeapons’ which lists all possible weapons

Everything is working great, but what I want to do after comparing the weapon number byte with the enum list is to use the Switch to attach the relevant model to the player.

Do I need to have a custom function for each weapon (PickupRifle();, PickupSword();, etc) which handles assigning the correct weapon model, or is there a nicer way to do this that I’m missing? I’m currently using an ‘Add Skeletal Mesh Component’ node to add the model, and the node itself contains the selection for the mesh to add (i.e. there’s no input node to change this with a variable)

Also worth mentioning that eventually I’ll need to do more than just add skMeshes, as weapon specific values will need to be copied across too. Best way to handle this presumably would be by making all of the weapons their own class - would they need to be of component type so they can be added and attached to the player in run time? Additionally, does that mean each weapon would need a pickup class and an equipped class? Because I don’t want to just attach the pickup class as they will have a lot of stuff I don’t want - collisions, unused variables etc.

Here’s my BP:

Thanks in advance, really appreciate your time

EDIT

Here’s my BP pasted on that website…

Yes theres few ways you can solve this:

Most straight forword would be holding mesh variable in pick up and read it up on pick up instead of using enums, if goal of your enums is to make weapon type selection easier, make blueprints with each mesh variable different,

Most common way is to keep pick up object and use as actual weapon instead of having single code that handles everything. you can make components invisible or straight up destroy them. make object handle fireing and use by using common events.

Those are standard practices ever since UE1

The idea of setting up Shooting functionality on the weapon itself is something I’d never considered, and solves a lot of problems, so thank you for that. Going your route with using the pickup as the same class also makes sense now, as I’m not attaching a new instance of the mesh but instead the same one lying on the ground. I can then proceed to destroy any unnecessary components.

You might be able to use pairing with the enums and pickup / equipped classes. That way you’d be able to sort other components / properties of specific weapon types after equip event, and keep it separate from the pickup (iwo, place in inventory) functions. It could result in a clean blueprints system, and perhaps be easier to debug or problem solve in.