Download

Questions about implementing weapon blueprints

Hey,

I´m looking for some help/input on the way I´ve implemented weapon functionality in my project. The idea is to have every weapon in the project (3 atm) spawn with the character (no weapon pickups).

  1. Im having my Weapon_ParentBP (purely functional BP, does not yet include a Skeletel Mesh, etc.) spawn in my FirstPersonCharacter. I pass my input from my FirstPersonController along to my character, which then can pass it along to my Weapon_ParentBP, all through Interfaces.

1.png

  1. In my Weapon_ParentBP I then spawn my Weapon_ChildrenBPs and “disable” all, but one weapon child (the weapon I want my player to spawn with):

fb5a3024d2fb1d8ddb1f099e90333da9d2018082.jpeg

The function and macro shown above look like this:

dda1d17bac56623757cde72a4d2d061fc71a6f70.png

840d6bada1394d65b1eeb7f846717b6887648fb4.png

Now,
Question #1) Is it the way to go to use the “Spawn Actor from Class” node when handling weapons? Should I just spawn the weapon every time I switch to it, instead of spawning all and disabling the one´s I´m not using?
Question #2) When calling the function SpawnAllWeapons in the Event graph, I get an infinite loop:

4.png

The construction script of this BP is completely empty. It works if I only spawn the Translocator BP and leave the others out to spawn. How do I fix this?

Thanks in advance!

I now have my Weapon_Children spawn via weapon switching and do an “Is Valid?” every time to avoid spawning them more than once.

Screenshot_9.png

Screenshot_7.png

My default weapon still spawns after Begin Play in my Weapon_ParentBP. The weird part is that it only works with my “Translocator” weapon and I get no errors during play. If I spawn my “Shieldgun” weapon after Begin Play however, I get an infinite loop again.

Screenshot_8.png

Error when spawning shieldgun on begin play.png

Im still unsure wheater destroying my Weapon_Children every time I switch weapons, or “disabling” them is the more performant way?

The three separate lines of code you have in this image can be condensed into one using Select nodes and Switches. Here is a very basic example:

The switch at the end replaces your branch nodes. If you needed to make a small change that would affect all of the weapons, you would only need to make the change once, instead of 3 times. Also, if you wanted to add in more weapons, you wouldn’t need to add in an entirely new line. You would just need to add it in your Enum and then update your Select nodes/Switches.

Thanks, I was able to shrink my event graph by a lot!
But I can´t seem to figure out which pin type to choose for the Select node. After all I need to select from different inputs (the different child actor BP references of my weapons) and pass them along to the “Is Valid?”

346f96d404391f089c5d478ed19ef6b793092281.png

Select nodes use a wildcard, meaning all the pins will use the first type that is plugged into it. You can’t mix types once one is defined. Notice how they all turned from grey to blue when you plugged your Translocator variable into it?

Anyway, I think you might be taking an entirely wrong approach to this problem. If these weapons won’t be pickups (and therefore won’t exist in your physical game world), then there is no reason to create an actor for each one. You’re better off just creating an array of structs and storing the weapon properties there.

I doubt structs will work for what I´ve planned in the end. But I think I can figure out the rest now.

Huge thanks for your help!