Rep Notify called on server, fires only on the server and not on the clients. What is going on?

Hi, I have a rather strange problem…
I have a variable replicated via RepNotify; The first time the variable is replicated, the RepNotify function is called on both client and server.
The second time the variable is replicated, RepNotify runs only on the server.
The rep function should only be called on clients, not on the server??

Inside my GameState I have a Server function called “ChangeMap” set as Reliable. The function is called correctly, so sentences like “are you sure you’re doing this from the server?” are not worth it.
Function

I then have the rep notify function:
Screenshot (53)

Here’s what happens on the first call to “ChangeLevel”:
Screenshot (54)

Here’s what happens on the second call of “ChangeLevel”
Screenshot (55)

WTF? Why is it called only on Server? Shouldn’t it only be called on Clients?
Am I doing something wrong or is there something strange?

RepNotify also gets called on the Server.

GameState is not owned by any clients so making a Server RPC is pointless.

Is the CurrentMission Type Replicated or placed in a level otherwise it can’t be replicated at all and it would always be invalid.

“CurrentMission” is a Primary Data Asset, it is correctly replicated the first time. The second one isn’t.
In the primary data asset a field called “Name” is modified and then the primary data asset is sent to the game state.
Online it is said that RepNotify is not called on the Server but only on the client. All my other RepNotify are also called only on Client.

RepNotify is generally also called on the Server for convince in Blueprint. OnRep functions in C++ is however not called on the Server.

RepNotify being triggered on server is normal for Blueprints, the node “SET w/Notify” is responsible for calling the server notify. At least this confirms you are running code on the server so it’s not a client->server RPC problem at this stage.

Considering your logs I would say either your property has replication condition InitialOnly, or you are not actually changing the value of the property. If the value you are setting is the same as before, it won’t be replicated. It triggers on server because the BP node triggers it unconditionally.

the rep condition is set to “none”.
I assume that the Data Asset is not replicated for the following reason:
-The server modifies the “name” value of a data asset, called Make.
-The server sends the modified data asset to game state, where it is set.
-In game state, the data asset reference changes from “Null” to “Make” and is correctly replicated the first time.
-The second time, I repeat the process, I always modify the same data asset and send it to the game state.
-the game state sets the reference of the data asset that goes from “Make” to “Make”. Although the values inside the data asset are different, the reference remains the same, so Notify is not called.

The question is, is there a way to force rep notify?

So your property always point to the same object - even if you change variables inside the object, the reference to the object is still the same.

Generally speaking you’d have to make the object itself replicated, and mark the property you are changing (Name) as replicated/repnotify, then you’d see it change… But considering the object is a data asset it’s probably not gonna work.

You probably should not modify the data asset and, instead, declare corresponding variables directly in the GameState class which you can then easily modify and use RepNotify on.

If you are changing multiple variables and want them all replicated at once (and get a RepNotify for it), use a struct.

If you need a notify event to trigger even if all the variables have the same value, then set your var/struct replication condition to “Initial Only” and call a Multicast replicated event yourself after modifying (or not) the variable, and pass the variable to the event. From the multicast event on clients, assign the variable from the value passed.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.