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"

Network Replication from Client-Side

Hey there, I'm trying to get a Lightbulb toggle on a switch working on Client and Server Side of my Game. I've watched the Intro to Blueprint Network-Tutorial and decided to setup a RepNotify to let the client know when the Light is switched on. The script is working, but only from the ServerSide. So if I use the switch in my Server the Light is toggling on both Client and Server, when using the toggle on my Client however only the clients light is toggling. I've tried using a Custom Event "Run On Server" and then Multicast it to all other Clients, but that doesn't seem to work either. How can I tell the Client to Ask The Server to Switch the Light of every client connected?

I'll attach my blueprints and two screenshots showing the issue.

Thanks in advance Max

alt text

alt text

alt text

alt text

Product Version: Not Selected
Tags:
more ▼

asked Sep 24 '14 at 03:24 PM in Blueprint Scripting

avatar image

PT_Max
23 5 10 11

avatar image PT_Max Sep 24 '14 at 05:37 PM

I've changed the Blueprint so a PlayerController Custom Event is called whenever the button is pressed. The Custom vent gets the light as a parameter and toggles visibility. When I test it however the client cant see the light he triggers, but the server can. So I press the button on client side and it shows up on server but not on the client. Why is that? Here are the updated screens

http://imgur.com/Y3DSYgd,N8Op0jY#0

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

1 answer: sort voted first

There are two main concepts within networking in unreal. The first one is variable replication, mainly changing a variable and replicating it always from the server to a given client. The second one is function replication, calling a server function from the client or calling a client function from the server, this is also called a RPC (Remote Procedure Call).

What you want to achieve is a mix of both, the client toggles the switch and has to call a server replication function to change a variable. The variable must then replicated to to all clients via replication and when the event happens on each client you have to update the switch accordingly. The client that calls the replication function could just update the light bulb on his box so that you simulate the behavior and it will look behave better in net work saturation.

Just as a note, make sure to replicate to all clients. The variable won't be replicated to the players that are hosted in the server itself though, there you have to update the bulb locally.

Hope I could help!

Cheers, Moss

more ▼

answered Sep 24 '14 at 06:57 PM

avatar image

Moss
6.4k 127 98 606

avatar image PT_Max Sep 24 '14 at 07:13 PM

Hey Moss, first of all thanks for the reply. I'm aware of the methods you mentioned and tried to use these methods. Therefore I created a Custom Event on my PlayerController which is basically the server replication event, since it can only be executed when the "Switch Has Autohoriy" function is replying Authority. Then I try to set the targets visibility. But how can I manage the functionality of replicating that Light back to the clients, when it is updated by the server? alt text

alt text

avatar image Moss Sep 24 '14 at 07:40 PM

You have to create a boolean variable in your light bulb BP for example, that you will use to handle the on/off state. The trick is to use RepNotify within the replication section of that boolean, it will then create a function in your BP that will be called when the variable changes, and so you can updatethe bulb.

Here is a nice crash course about replication in BPs: https://www.unrealengine.com/blog/crash-course-in-blueprints-replication

Cheers, Moss

avatar image PT_Max Sep 24 '14 at 08:25 PM

Thanks so far, but I just don't get it. I get the fact, that RPC are calling form client to server but how can I execute them then....I don't get that: The Multicast seem to be the ones I'm looking for, since I want to execute on every machine. however it says "Replicated to All (if server)"....well this isn't very helpful since I want to execute the whole thing on a client and still let the server update every clients machine. Now it's pretty much vice versa than before.

Before: Server Light is toggled, carless of whom used the trigger. Client Light is only triggered, when Server used the Button

Now: Server Light is toggled when Server is using the Button. Client Light is triggered regardless who is using the button.

Sorry for being such a pain in the .... I just don't get the concept....

alt text

Addition: When using "Run On Server" the client clearly doesn't own the Trigger, so it doesn't execute the trigger whatsoever, the server on the other hand is handling the trigger well then.

avatar image Moss Sep 25 '14 at 07:42 AM

I will try to setup a test scenario this evening (I have no running engine right now). But what you Press E you should send the event to the server I guess. This is normally done from a PlayerController which the client owns.

For example:

The PlayerController has authority in the client over its own so you can send a server call from there, once on the server side you search for the bulb (a trace or even a simple radius check to see if the player controller is able to switch the bulb). If you found a light bulb (this is applicable to any BP if you build a usable system) on the server you then change the variable (is on) accordingly and switch the bulb itself on the server (so for those clients that are local to the server it is automatic). What you have done this way is to reuse the player controller to route the 'use' action to the server which in turn performs the 'use' action on the bulb resulting in the replication of the 'is on' variable to all clients.

To make the light switch instantly on the client that actually switched it I would switch the light bulb locally (without changing the variable locally though!) and then sending the server call from your PlayerController.

As I said, I will setup an example scenario on how to perform such a thingy ^^

Cheers, Moss

avatar image PT_Max Sep 25 '14 at 11:10 PM

Hey Moss I got it working...kinda. I can toggle the light with both Server and Client. However the server has to toggle the light a few times before the client can use it but idk why actually

Edit: Oh ok, there seems to be sth wrong with my Check Trace, since it's always taking the servers trace instead of the clients, so I have to look at the Button with my server and then i can toggle it, with my client.

Edit2: OK, I just had to move my Check Trace before my "Run On Server"....of course^^

Now I've got a fully functioning Blueprint :)

For all the people out there having the same issue, here are my Blueprints:

Pawn alt text

Player_Use_Interface alt text

Trigger_Button alt text

avatar image Moss Sep 26 '14 at 07:26 AM

Also you have to check the initial state of the variable. For example if Light On is TRUE by default it wont be replicated because there isn't any change.

This will lead to the issue that you have to toggle it off and on to function correctly. To fix it you have to turn the light depending on the default state of the variable or in the constructions script or the begin play event.

Nice it worked!

Cheers, Moss

avatar image PT_Max Sep 26 '14 at 11:54 AM

Well I do in the yellow section Moss :)

avatar image kindfox Nov 20 '14 at 11:50 AM

this explanation is so helpful, thank you !

(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