That is, even if the value of Var2 changes first and then Var1 (in the same tick):
Var2=1;
Var1=2;
The OnVar1Change() function is executed first on the client and then OnVar2Change() is executed.
I would like to know if I can trust this. Is the replication order guaranteed?
Or should I look for a logic that does not depend on the order of replication?
Because I could replicate one structure instead of the two separate variables, like this:
I’m not sure how replication actually works… until now I thought that in the case of the structure all members (16 bits) would be replicated… And I thought the same in the case of an array…
But if it works like you say it really is a paradigm change for me. I was very concerned about inefficient use of the network.
but i can say i wouldnt worry about the efficiency of one small struct, especially when its OnRep as it’ll replicate when it can, not forced like a RPC
Not only do I need it to send as few bits as possible (so as not to saturate the network), but I also need it to be as fast as possible.
One variable is the type of weapon.
The other variable is the amount of ammunition.
Sometimes I just need to check the ammo value.
Sometimes I just need to check the type of weapon.
And sometimes I need to check both things at the same time.
Maybe I need a more efficient replication method than Rep_Notify to do that.
Yes, it’s for the “HUD”
It was important that the functions were executed in the correct order.
Suddenly it started malfunctioning when switching weapons (it used to work fine before).
The ammo from the previous weapon was displayed on the current weapon.
Then I realized that the values changed on the same tick and that the notifications were not being executed in the correct order.
You seem to be right. Only the members of the structure are replicated.
However, I still have doubts about the bits that are sent over the network.
The socket is going to send a block of bytes (The size of the structure).
If you send fewer bytes the other members of the structure will end up with random values (garbage) or Zero value. And that’s in the best case because it could cause an exception and crash the program.
At least in my experience with sockets, when you send a structure over the network you must send a block of bytes the same size as the structure…
I can think of a way that if you send the structure in pieces, it then has to be recombined on the client side. But if they do it like this I would like to be sure. Everything that does not add up subtracts.
that’s out of my league, BUT i really, really don’t think you need to worry about this. micromanaging performance at this level without a problem is gonna slow your production to a crawl.
I don’t really know… it’s a shooter game… There are eight players shooting very frequently.
The only thing I know is that it’s not good idea to overload the network.
That’s why I want to send as little data as possible.
I hope someone can solve this doubt.
If I really didn’t have to worry about that, that would be great… I would use the structure and not worry about the order of execution of the functions.
you dont have to worry. remember RepNotify will only fire when its ready (network safe) yes this means the player gets a delayed HUD but thats what lag is, we’re all used to it.
that said if you fire 35 shots, it doesnt update 35 times. it updates once when its ready with a value between (x and 35) if that make sense.
or if it makes you feel better, lets say thats exactly how Lyra or even Fortnite would do it
Reliable RPCs are what could overload the network which is why you should use them sparingly
I’ll check them to see how often they are executed.
I would like to find information about how replication works internally (I’ll look in the documentation)
I was lucky because you explained some things to me…
But I think I need to know everything about it.
So I will know exactly what to do in every situation.
they are all unreliable so its fine, but that means they could be dropped/lost so unreliable is good for fast but non essential things like FX. (lets say a muzzle flash if you multicast that)
also things on tick since if you drop 1 tick no big deal, you’ll get the next. ie say movement input.
Only use reliable for absolutely essential things that would break the game if missed.
The order of Variables/RPC’s in a packet has no bearing on the processing order of them. No order is guaranteed in any processing outside of Actor Tick Grouping.
There are no guarantees of receival on any data marked unreliable (no resends). Yet, Reliable just means you’ll get it at some point (resend)… even if that means it’s irrelevant by the time you do get it.
e.g. Resend (value: B), Next update server tick (value: D)
The first replication of a struct is the entire struct and current values. Subsequent replications are only the values that have changed (Network/Bandwidth && Processing Optimization). These sends will not include a zero/nulled structure. That would defeat the purpose of only sending the changed values. Struct designation and value.
Grouping “Like && Action Specific” replicated variables together in a struct is always a good approach.
Replicated variables should not require ordered sequential processing. Look at combining them into a single variable representing 2 or more sub states. Enumeration is a good option here.
HUD based variables, Health, Score, Ammo etc, should be RepNotify.
Client-side prediction approaches to data can be helpful. For example you fire a shot and deduct ammo locally to maintain your UI and current states of things. The servers update will “clean up” any mishaps.
Keep in mind there’s no guarantee the server will receive your Shot RPC. Regardless, the next shot it does execute will correct the owning client.
Packets are processed and sent on tick start.
A packet received on Tick 100 will be processed at Tick 101 start, and any outbound response (RPC, replicated var) will be sent on Tick 102.
e.g. You fire a shot and RPC the server to shoot.
Tick 100 RPC is received.
Tick 101 it’s processed, Shot Fired and Multicast Called. Server executes the MC logic.