Lets Make: Weapon in Blueprint from Blank Project

GOAL : A Crowbar and a Shotgun that can break Apex destructibles and move normal physics actors and damage pawns too.

EDIT:
Right I was going to post this but then the f*cking electricity shut down and it was back to drawing on the walls with charcoal. Anyway now I’m back in the 21 century and here is the beginning:

Step 1: make your BP of your gun. Add a collision component and set it to overlap all. Now make a Custom Event and put a placeholder print string so we know when or event is called. You are DONE!

http://fc05.deviantart.net/fs71/f/2014/084/2/e/t5_by_zerodollarz-d7bmcni.png

Step 2: Go to your Pawn do this:

http://fc06.deviantart.net/fs71/f/2014/084/4/9/t6_by_zerodollarz-d7bmcno.png

this will attach the weapon to a socket (that you have to make in your SkelMesh(mine is called weapon))
and it will call the event Fire when you leftclick

Step 3: Collide/Destroy Apex destructibles.
If you want your weapon( or its bullets) to destroy the apex actors, you need to make sure they are both have the same USE ASYNC SCENE value.

Thanks for sharing I’m gonna give this a shot when I get home for my melee weapon.

Please keep the information coming!

Midnight do you mind showing your content browser and a bit more of the Blueprint window? I’m trying to set this up and my weapon doesn’t get attach on play, what else am I missing in the setup?

I don’t mind but that is all I have :slight_smile: (the other things are WIP and i don’t want to confuse because they don’t work)

Check your “attach to actor” do you have a custom socket in your skeletal mesh , if not ,you can attach “Camera”-“In parent” to test will it work,

Also make sure your weapon has a mesh so it casts shadows , sometimes it gets attached out of your FOV and seeing the shadow move with you, can tell you if are you going in the right direction. :slight_smile:

thanks alot dude, i really needed this

EDIT:

OK I removed my other complaints. This works wonderfully! The only issue I have is that for some reason the thing attaches in weird directions… Any idea how I could correct this? Does it have something to do with the way the skeletal mesh is set up? or is that something I could do in the Weapon blueprint, so that it changes its rotation?

Go to the Blueprint of the weapon and rotate the mesh in the components tab. Just keep guessing which direction you need to rotate until you get the right one :stuck_out_tongue:

DUH! That was deceptively simple. Other things I will note is this -

If your gun has Physics, it will not attach to your character!
If your gun is set to collide with the player, it will block any traces you may be drawing out of your character. It’ll also push your character around because well… its colliding.

My fix was simple -
before the trigger that attaches the gun to your character, make sure to change the guns physical properties. You can do that with Set Collision Enabled and Set Simulate Physics targeting the Collision box you have under components.

Using this general idea, could you in theory set multiple weapon sockets on a pawn that a weapon can connect to, and just change which socket is attached in the Attach Actor to Component function?

Guys I’ve been playing around more with my weapon setup and I wanted to share; I’ve deviated from Midnight’s initial setup by creating an attachWeapon function that’s called at BeginPlay so they are always attached to the player.

Just to explain what’s happening in my blueprint, I’m crafting a weapon system similar to Zelda. Players can Attack, Block and Holster their weapons which should be pretty self explanatory on the blueprint.

[Edit] Just realized I didn’t compile before I took a screenshot, the blueprint works fine.

Is the “Attach Actor to Component” aspect something you can put into a Blueprint’s constructor, so that if a pawn is spawned, a weapon(s) is automatically equipped to the appropriate socket(s)?

Yes you could do that. Take a look at my Blueprint, I switch between the ‘weapon’ node and the ‘weaponSheath’ node.

I’m not sure why don’t you try it out and share?

Doing so now; I wasn’t in a position to do so initially, as I was at work. I’ll report my findings when I try it out!

So I’ve got a couple weapons working thanks to this thread. I have 99% of the blueprinting done for equipping the weapon, checking to see if a weapon is already equipped and dropping the current weapon if so, and so on. Right now however, even with only two weapons, I can see an issue coming down the pipe - Consistency. Lets say I have 10 weapons, all based off the first weapon I made, the only thing that changes really is the fire rate and the type of projectile. Then lets say I have a realization that I could do the nuts and bolts part (say, dropping a weapon when a new one is equipped). Now I’m stuck changing 10 weapons to make sure its consistent.

Let me show you what I have so far, tell me if I’m doing this in a crazy way. I’m trying to make the Pickup and Drop logic as generic as possible.


some of these comments are dated actually, so try and pay no attention to them.

You can make 1 weapon that has all the functions and expose a bool to enable/disable each function. Then you just extend from it (make a child BP) and change the mesh and bullets…
(In content browser right click on a BP and Create BP based on this. This child wont see the parents code at all. The only thing you can change is the Defaults so it is worth exposing as many vars as you can )

Hi first of all thanks for the nice tutorial and all the answers, I’m having trouble to manage how to make weapon cycle script, I have done several guns but only can fire them with diferent imputs, I’m really noob at game creation withowt programing knowledge and all my experience comes from a time messing with NOD editor from Vampire The Masquerade redemption back in the 2000 :stuck_out_tongue:
So I will really apreciate someone give me step by step advice in how to make a weapon cicle script, thanks a lot:)

In other order of things I managed to solve this:

You can drag and drop a mesh into a bone of your skeletal mesh editor for preview purposes, then you have to rotate THE SOCKET where your gun attach to fit the position, as you have the visual reference its a lot easy than figure it out, you can even play the diferent animations to see how they will be

Hope this helps and thanks in advance:D

What you need is an inventory manager. (it is complex and requires either casting or interface interactions)

I will try to explain the basics as simple as I can.

FIRST : BASE ITEM
In it make either custom Functions/Interfaces like: fired (and very important) **unfired ** or you weapon wont stop shooting after you release the button…
add things like equipped and unequipped also Picked and Dropped

SECOND : all your weapons extend from this item aka
(In content browser right click on a BP and Create BP based on this. This child wont see the parents code at all. The only thing you can change is the Defaults so it is worth exposing as many vars as you can )
then in your childBP you use these functions to trigger what ever you want

THIRD: In your pawn you must make an array that collects all the weapons you have picked up. (you have to hide the unequipped and picked weapons , also you have to attach them to the pawn)
Then with the 1234567890 keys you can get an Item with index #0 (for the first item ) and then you SET this item as the equipped weapon.
or use the mouse wheel to increase/decrease the index(+1 or -1 ) thus getting the next or previous weapon

FOURTH : Now you are ready to shoot them. In your Pawn Get you equipped weapon var and drag of it and when you search “fired” you should see the function of your ChildBP .

Thanks a lot for your fast answer I will give it a try :wink:

I am working on exactly this as well right now. This thread has helped a lot as I’m new to everything! So thank you everyone!

I wanted to post as I have some working (but messy) blueprints set up to do the following:
Pick up weapon and ammo
Equip weapon when picked up
Fire projectile and reduce ammo
Never pick up more than max ammo
Use mouse scroll to switch weapons
Display ammo and weapon type on hud

If anyone wants to see specific code I can post it up for you.