Are all replicated variables updated from the server before calling RepNotifies?

Hello, i want to know if the replicated variables updated from the server are all updated first and only after that will it start calling the repnotifies? Or does he call the repnotify immediately after updating the replicated variable? Thank you

Hi there,

The properties are updated first, then the rep notify is called. So by the time you get the rep notify, the property will be up to date.

If you want the old value, you can add the value as a parameter to the rep notify, and it will pass the old value in that case.

So if i have 3 properties that are going to be updated from the server he does something like this?

foreach(Variable to be Updated)
      Variable = ValueFromServer;

foreach(Variable to be Updated)
      OnRep_Variable(PreviousValue);

Because i have a character actor where i call EquipWeapon (which sets bIsEquipping to true and sets Weapon to the new weapon) PostInitializeComponents on the server (ROLE_Authority). The repnotify for bIsEquipping is called on the client but Weapon is still null so it crashes when i call EquipWeapon.

Ahh, this is because the weapon actor hasn’t come through yet, so it is NULL. This is an unfortunate side effect of how replication works in UE4, but there is not much we can do here (we don’t know that those two properties are dependent on each other).

The best way to handle this is to probably use a rep notify for the actual weapon object, and then react to that coming in instead.

But apparentely this only happens when i call EquipWeapon on PostInitializeComponents, if i call it during the game it will work. The only reason i use the boolean to repnotify is because actually i have 2 weapons (weapon right and left) to possibly dual wield and i want to do a different animation for equipping single and double, so with 2 repnotifies for both weapons might not always have the correct value for the other weapon to select the right animation. Previously i did the equip first through the server and then did a Client multicast function to replicate to all clients, but i shouldn’t abuse Client functions right?

It probably works the second time since the weapon actor was already on the client, or in some cases it’s a timing thing.

The main take away is you can’t rely on when exactly a actor reference will arrive, and have to assume they will arrive out of order with respect to other actor references, and code around it.

You can add a rep notify to both weapons, and then don’t react until both are not NULL for example.

Ok, so basically with repnotify i can’t trust that the variable dependencies (even if they were both changed on the same function) will be there when it triggers the OnRep (a bool is much faster to transmit than a Weapon, so that’s probably why it reaches first). I just assumed that the server at the end of the tick packages all the variables that are different from the client and sent them all in one take. I guess that’s not the case and they come as they go in different client ticks. I will try to do what you suggest then. Worst case i use Client functions, but that means that the action will have to start on the server first instead of the originating client, which is always bad for responsiveness if your net is not good. Thank you :slight_smile:

That’s correct for object/actor references. For int’s, floats, and other non object properties, they are guaranteed to arrive together if they were changed together.

That type of information would be very helpful to be documented, because it’s those little details that make you lose so many hours :stuck_out_tongue: Thank you :slight_smile:

Np, I’ve make a note to document these things better!

I think one of the most complex things in UE 4 is replication, i’ve been working for weeks full time, trying to understand the concepts and making everything work with repnotifies and client functions and how everything ties together, and i feel that there is still very little in depth documentation. I’ve been reading the UE 3 documentation and it helped, but i still found myself with a lot of questions, and i’m sure i’m not the only one :slight_smile:

Is this true if there are enough properties to make the update go beyond the bunch size boundary? At least for initial replication I didn’t think this was the case.