x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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?

Product Version: Not Selected
Tags:
more ▼

asked Dec 17 '14 at 07:11 PM in Blueprint Scripting

avatar image

GG04
126 8 12 16

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

Doug Wilson

more ▼

answered Dec 17 '14 at 07:30 PM

avatar image GG04 Dec 17 '14 at 07:42 PM

Hi Doug

This worked perfectly. Thanks a lot.

avatar image GG04 Dec 17 '14 at 07:53 PM

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.

avatar image Doug E ♦♦ STAFF Dec 17 '14 at 08:13 PM

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.

avatar image GG04 Dec 17 '14 at 08:21 PM

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

avatar image Doug E ♦♦ STAFF Dec 17 '14 at 08:43 PM

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.

avatar image GG04 Dec 17 '14 at 08:54 PM

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.

alt text

alt text

avatar image Doug E ♦♦ STAFF Dec 17 '14 at 09:41 PM

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.

avatar image GG04 Dec 18 '14 at 03:51 AM

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?

avatar image GG04 Dec 18 '14 at 03:51 AM

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

alt text

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).

alt text

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

alt text

alt text

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.

alt text

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


(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question