Cannot get gun to fire after casting to character

Hello everyone

I’m trying to modify the default first person template to have the gun that you pick off the ground to already be in my hands at begin play. Essentially I want to skip the step of walking to the gun to pick it up. This is what the default BP_Rifle line of code looks like. https://imgur.com/Uz9TKnH

What I have done (along with adding hit scan and a secondary fire. This is not relevant to the question but that it why that part might look different) is I have followed this tutorial:
https://www.youtube.com/watch?v=mSCPg3d5Kgg&ab_channel=MattAspland
This got me able to walk around with the gun in my hands but I am still unable to fire either of the modes. I tried to trouble shoot it by adding a call/bind event between the two BPs, however I am sure this was the wrong thing to do since it is not working and I just only learned about this stuff today. This is still my first week learning this stuff.

Here is what my BP looks like for this section of my BP_FirstPersonCharacter: https://imgur.com/eCnUY8b

And this is my BP for BP_Rifle: https://imgur.com/r94Kwd1

If you have any idea as to what I have done wrong, what I need to add, or if I need to revamp the whole thing, please let me know!

Thank you all so much :slight_smile:

On spawn create a reference to the gun. Then simply use the reference to call the fire events.

Spawn → Set Gun Obj Reference → attach etc.

Fire Input pressed: Wep fire Event (Gun Obj Reference)
Fire Input released: Wep Stop Fire Event (Gun Obj Reference)

I cant quite seem to get it to work. I don’t think I fully understand how to attach the gun object reference to the fire/stop fire events. Could you go into a bit more detail?

Thank you for your help.

On spawn I’m creating a reference to the spawned actor (Weapon Obj Ref). When firing I’m using that reference to call an event in the weapon class directly. Same applies for stop firing.

In the Weapon class I have a variable reference for my character class. I pass “Self” to it in the spawn node. This sets a reference to the character.

These references fully negate the need to do any casting for the two obj types.

When I switch weapons I simply update the Weapon Obj Ref. When I drop a weapon I set the variable to Null by using a set node with no value passed.


In your BP_Rifle Class create the two custom events… Fire Weapon, Fire Released. Apply your firing and stop firing logic to those events.

image

You are a legend. Thank you so much. One more question if you dont mind, but this seems to have broken my First Person Character Reference in my BP_Rifle. My animations are not playing, nor is my line tracing.

open BP_Rifle, In the Variables list find “First Person Character Reference”, select it.
In the Details Panel tick “Expose on Spawn” and “Instance Editable”.
Compile and Save!

Open the character class. Find the Spawn Actor of Class node. Right click on it and select “Refresh Node”. The first person character ref pin should now be shown. Get a reference to self and pipe it to it. Reference the first image in my last post.
Compile and Save!

Homie you are a godsend. Thank you for everything

1 Like