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"

Networking, opening a "door" through all clients

I have a player pawn, when I press a button through has athourity, it sends a raytrace out and when it hits the door actor I calls a custom event in the door actor that do stuff, (the custom event in the door actor has executes on all), but it only works when the server calls it? how do I make it work for all clients?

Product Version: UE 4.14
Tags:
more ▼

asked Nov 26 '16 at 03:05 PM in Blueprint Scripting

avatar image

Lathost
5 7 11 13

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

1 answer: sort voted first

I just finished working on my network door, so I can tell you how I did it. I have a BP called Interactive Door that is inherited from my Interactive Object BP. In the Interactive Door object I have a custom event called "Interact". This even checks for Authority, and then flips the ClosedOrOpen boolean value. ClosedOrOpen is a replicated var with Rep Notify. In the same BP there is a rep notify function called OnRep_ClosedOrOpen that checks to see the value of ClosedOrOpen and rotates the door to the closed or open position accordingly.

Back in the player controller (you could also put it in the character BP), when the character presses the E key to interact with the door I have the client call a Run on Server / Reliable custom event called "Server_InteractWithdoor". This event on the server side calls the "Interact" event on the door that is in front of the player. Then the code I mentioned in the first paragraph replicates that to all players and they all see the door open as well as the door being open on the server for collision purposes.

If you have any questions, let me know.

more ▼

answered Nov 26 '16 at 03:51 PM

avatar image

Dartanlla
2.6k 62 26 281

avatar image Lathost Nov 26 '16 at 05:07 PM

thanks for answering me! :D but probably not understanding you very well, But what I have done, is in my character BP I cast to the door PB when I hit something with raytrace by channel, and then run a custom event that has run on server (reliable), then that one runs interact from the door BP, but where should I turn the OnRep_ClosedOrOpen function and how on earth do I make it a rep notify? and also where do I set the closed or Open? var that has RepNotify checked?

avatar image Dartanlla Nov 26 '16 at 05:25 PM

A screenshot should help. First notice on the left side there is a variable named ClosedOrOpen. Then in the top right corner notice it is set to RepNotify. Setting that automatically creates a function called OnRep_ClosedOrOpen. You can see that function in the center. This is the code that runs on each networked client when the value of ClosedOrOpen changes on the server. This function is responsible for moving the door to the open or closed position in the world.

alt text

interactivedoor.jpg (195.4 kB)
avatar image Lathost Nov 26 '16 at 05:33 PM

okay, cool! the more you know! but should I in the Interact event after switch has authority use a flip flop to toggle the var ClosedOrOpen? sry for not understanding everything! :/

avatar image Dartanlla Nov 26 '16 at 05:35 PM

Yes, in the interact event on the server side use a flip flop to change the value of ClosedOrOpen. Then the rep notify will take care of the rest on the clients.

avatar image Lathost Nov 26 '16 at 05:39 PM

It works tho the client can't open the door, only the server version?

avatar image Lathost Nov 26 '16 at 05:40 PM

because the client doesn't have authority?

avatar image Dartanlla Nov 26 '16 at 05:54 PM

In the player controller or the character BP when the open door key is pressed you have to call a server event on the player controller or character BP that then calls the interact event on the door on the server side.

avatar image Lathost Nov 26 '16 at 06:04 PM

yes! that was It! after I press the key I run a custom event that runs on server then that custom event runs the raytrace and stuff! Thanks so much for helping! :D

avatar image Dartanlla Nov 26 '16 at 06:08 PM

Yep! Glad you got it working. Be sure to mark the question as resolved so other people with the same issue can find the solution.

avatar image Lathost Nov 26 '16 at 06:28 PM

sry for not being the brightest thing in this world! xD, but do I just add resolved to the title because otherwise I can't find anything to mark this question as resolved?

avatar image Dartanlla Nov 26 '16 at 06:31 PM

Just click the circle with a check mark in it to the left of my first answer to accept that answer as the solution.

(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