Can't make my gun shoot

I’m a beginner in UE4, and I’m trying to make an FPS game. In my game you have to pick-up or switch between guns which you can find in the level, and then kill monsters.

So far I made a character with movement, which can pick up guns when pressing “E” through a blueprint interface. When the gun is picked up, it is added to a socket of the character’s mesh. The Gun itself has a socket at the end of the barrel where my “BP_Projectile” spawns. “BP_Weapon” is aparent of “BP_M4”. BP_Weapon has two custom events (Start/Stop Shooting) which just change the “IsFiring” boolean. These two events are then used by their childs before spawning the projectile just to set the boolean.

My problem is how do I call these two custom events inside “BP_MainCharacter”. I tried using “Cast to BP_Weapon” but I need an object refrence. I made a variable of type “BP_Weapon” (Object Refrence) and plugged it in but obviously it doesn’t work. I know that the Cast to node basically makes sure the object plugged in is the right one, and if it is I can then access it’s variables and some other things. I’m sure there are other ways of doing the whole gun system but this was the easiest for me to understand.

I watched/followed some tutorials but I couldn’t find what I was looking for…




But you attached the gun to the character, right? How did you do that with a reference?

I used “Get player character” then “Cast to BP_MainCharacter” and accessed the skeletal mesh

You have the character here

if there is a reference in the character, you can set it here.

1 Like

Hmm, so if I understood correctly, I can set the “Weapon” variable after casting like this:

Now I can hear the “Play sound at location”, but the gun doesn’t seem to shoot. It has some print strings when the projectile hits something but that does not appear. I can’t even see the bullet coming out of the socket.

I don’t think the player is the parent, I don’t see you adding the gun as a child. Maybe change this

image

to ‘get player character’?

Yeah… that made it work… It’s gonna take me some time to fully understand the way i have to refrence objects…
Thanks a lot!

1 Like