Best way of associating Weapon Blueprints with Player Blueprints

Hi Everyone,

I currently have a Blueprint for my player, a Weapon Base Blueprint for my weapons, individual Weapon Blueprints for each weapon type and finally a Pickup Base Blueprint and assorted Pickup Blueprints.

Now I’m abit stuck for knowing how to associate with individual Weapon Blueprint with the Player so I can cast to them. Ideally I’d like to be able to add the individual Weapon Blueprints to the Player Blueprint, but this is not possible.

Ideally I wouldn’t waste time adding each Weapon Blueprint to each level, nor would I want to move all the weapon data from the Weapon Blueprints into the Player Blueprint. The latter is something that the ‘FPS/TPS Framework’ on the Marketplace does, which is great for a quick prototype, but not for a functioning weapon framework :frowning:

Any ideas?

Hello,
when you have a new weapon, attach it to your character and store it in a variable “weapon base blueprint” the parent of all your weapons. Then when you’ll need infos, you’ll can have them from this variable, and as all your weapons are children, it’ll work for all of them.

Don’t forget to set the variable empty if you don’t have a weapon and to use a “is valid” to check if variable is empty or not.

1 Like

Thanks, I’ll give that a shot.

I’m playing around with it this morning and still abit confused and have a few of more questions:

  1. What do you mean by “when you have a new weapon” and “attach it to your character”?

At the moment I’ve set it up so that there are 7 inventory slots on the player, 1 for each weapon type. This inventory is a Struct Array. Each slot in the invetory has a variable “Has Weapon?”, which is set to true when a weapon pickup of that type has been collected for the first time. My Next / Previous Weapon runs a ‘ForEachLoopWithBreak’ for the inventory to check for this flag before either equipping it or moving onto the next slot.

I can’t spawn each Weapon Blueprint within the ‘Begin Play’ event.

Nor should the way to handle this to be having a Weapon Blueprint for each weapon placed in every map and given to the player on ‘Begin Play’ but I can’t work out where you’re suggesting I place the Weapon Blueprints and how I attach them to the player. Placing each Weapon Blueprint in every level and attaching them to the player seems like a waste of time and adds to the risk of creating bugs to me.

  1. When you say “store it in a variable “weapon base blueprint””, do you mean an object variable?

I can’t find my weapon parent “Player_Weapon_Base” as a variable n either the class or object list when creating the suggested variable within the Player Blueprint.

This is a new area for Blueprints for me so any further details & help would really be appreciate. And if I’m handling them completely wrong and there is a better way of doing things, let me know. I’d rather do it right than get help continuing to get it wrong :slight_smile:

Sorry, i thought that you were wielding only one weapon at a time (dropping the old one when you have a new one) and not having all of them ready to use when picked up.

Then you can create a variable “weapon” that you “attach to” (target is scene component) your character mesh and Set those variables (using an integer variable “weapon type” ) when you change weapon like this :

and then set your projectile variables on spawn with the weapon type value (defined on select).

Edit : you need to detach attach to have the new socket being considered. (and may be chang anim bp state too.) If they are all on same socket, you don’t have to detach, only set weapon mesh.

1 Like