How to implement PullTrigger Event?

Hi!

I have two blueprints. One is the character that the player controls (Character) and the other is the weapon (Weapon).

The player presses a key which fires a custom event on Character called “PullTrigger”.

I need Weapon to know when the event has happened, and to replicate to all other clients.

What I don’t understand is how to allow Weapon to see if Character has called the event. I’ve watched the replication tutorials and the blueprint communications tutorials, but they don’t seem to cover something like this. Is it possible?

Hey GG04-

You should be able to cast to the Weapon blueprint when the PullTrigger event fires. In the custom event you can add a “Get All Actors Of Class” wired into a “For Each Loop.” From the loop’s array element pin you would then use a “Cast To…” node to cast to your weapon and then connect the As Weapon pin to whatever it is inside the Weapon that needs to be aware of PullTrigger.

Cheers

Hi

This worked perfectly. Thanks a lot.

Quick question, which event would you use to initiate Gun’s actions? Right now, I’m using Event Tick, but it seems that this is causing the bullets to fire in twos.

EDIT for viewers:

This was actually due to the client and server playing different versions of the event. The client played its local version and the server played its own and cast it back to the client, making it look like the gun was firing twice at a time.
The fix is to make sure that only the server is allowed to spawn bullets though the Switch Has Authority node.

To go along with the steps above, I would create a function inside Weapon. Then whenever PullTrigger is called from the Character, it can make a call to Weapon’s Function which would control the weapon’s behavior.

Wouldn’t something have to tell the blueprint to listen for the call? Like Event Begin Play or Event Tick?

You’re essentially calling the Weapon Function from the Character. Anytime the PullTrigger Event fires it will make the call to the Weapon BP and the code in the function will run.

I must be doing something wrong. Using breakpoints, I can tell that Character executes PullTrigger function using the Cast to Gun, but Gun doesn’t receive any information and doesn’t react.

Here’s what the blueprint looks like (note: substitute “TrigYanked” for “PullTrigger”. Also, “TrigTanked” event in Gun blueprint never executes.

24343-screen+shot+2014-12-17+at+3.53.14+pm.png

If you connect a PrintString node to TrigYanked do you see anything print to the screen during play in editor? If it is still not responding I would try setting up a function inside the Gun and then call the function rather than an event.

Okay, your solution worked. I also came up with an alternative solution that works as well.

Here’s the working solution for now. Essentially, you’re pressing the mouse button, the server checks to see if you have a gun via get overlapping actors, and then executes a function that is run on the server. The function calls an event that finds the gun, casts to it, and tells it via bool that the trigger is depressed (the bottom part just does the reverse).

This is your solution, which finds a gun, and casts to it to execute the contained function. This works too.

This is the complete weapon blueprint, the CompareFloat checks an assigned identity float value to determine ownership, the sequence node and delay allow for automatic fire.

24375-screen+shot+2014-12-17+at+10.34.01+pm.png

This part is a simple workaround for lack of knowledge in how to modify ownership. Without it, either player can fire each other’s weapons, which we obviously don’t want. It assigns a random float value to your actor, which upon picking up the gun, the gun also takes on your float value (identity code). The gun will only fire if your identity code matches the gun’s.

Hope that helps anyone who is trying to do something similar


Anyway!

Here’s the problem I’m having. You can see that in the Weapon blueprint, there is a socket on the gun’s mesh (called Muzzle), where projectiles exit. This works perfectly, except when my character is crouching, the projectiles don’t follow the muzzle and instead don’t seem to realize that the gun has moved down.

I think the solution is to make a bunch of other sockets and manually tell the gun where it should be in every situation. Am I right or is there something I’m missing?