Download

RepNotify Function only executes on Clients not on the Server

Hello Community,

First of all, the upcomming pictures are very big. Open them in a new Window, to scroll horizontally.

this is not my first RepNotify, but the first iam struggling with. What it is about:

I created an AmmoPickUp Actor. When the Player moves over it (enter its collision sphere), the PickUp content should be added to the Players AmmoBackpack (represent by the RepNotify Variable).
The RepNotify Function should update the Players HUD, to see the content of his AmmoBackpack.

As the client, all is working correctly. But as the Server, the RepNotify Function never gets executed. As i am aware that the Function only gets called, if the RepNotify Variable does actually changes, i added a print as a proof for debugging.

The only difference to my other RepNotifies is, that this one is an array.

Any suggestions?

PickUp.png

RepNotify.png

The Video shows, that the Array is changeing (print in green) and that the RepNotify is called only on the Client (print in white)

I did some testing with normal variables and they all get the RepNotifyFunction to execute, but only if i am using the “set var” node. The “incrementInt” node leads to the same problem. So i am supposing, that is has something to do with the “set array element” node.

Edit: After some more searching down this forum, i came up with those two postings:
Set Array Elem problem
FEATURE REQUEST - Set Array Elem Repnotify

The first one is open end and has no result, but the second one mentioned to add another var (a boolean), that is altered with any array change and THIS is RepNotifing the function for the array. The array itself will get back to “replicate” only.

I will test it and post a result here.

Hmmm… after some testing i came up to an “yes and no”:

YES: A RepNotify Boolean solved the problem above and the server now works as intended, but…
NO: The Client stops working. The problem is here, that the boolean gets replicated bevor the array. So that my widget got old information (one step behind) to work with.
To solve: I leave both (the array and the boolean) on RepNotify and uses the “switch authority” to save up some Hardware ressources.

Iam not that satisfied with the result, but it works at least. As long as i have much much more work to do, i leave it here with a marking in my code and will go on with other problems :smiley:

What’s the root cause of this?

I don’t know if the same applies for Blueprint, but in C++ RepNotify/ReplicatedUsing-functions only get called on clients on replication. The server, after setting the replicated values, has to call the OnRep-function manually… because the server is responsible for setting the replicated values and does not recieve them as replication, the server has to call the RepNotifies manually.

Try calling the RepNotify-function manually on the server after setting the values on the server. That way it gets called manually on the server after setting the replicated values, and the clients will automatically call it when the values get replicated.

On server:

  1. Set your array to be replicated and have it have some RepNotify function A
  2. Set values in your array
  3. Immediately after setting the values in the array, call A manually on the server

On client:
A should be called on replication.