Try to take advantage of the quantization functionality that already exists. e.g. FVector_NetQuantize. These will greatly reduce the size needed to replicate this state over to clients
First Question: I don’t understand what exactly is FVector_NetQuantize function? What does it do?
Second Question: How does it improve network performance and reduce size of replicated data?
It would be really helpful if someone could explain in detail. Thankyou in advance!
FVector_NetQuantize is not a function, it is a type. It is just a very thin wrapper around a regular FVector. The only difference is that the net quantized version has a custom NetSerialize implementation, which rounds each vector component to a whole number when it is replicated. With FVector_NetQuantize, at most 3 * 20 bits = 60 bits will be sent over the network instead of the usual 3 * 32 bits = 96 bits for an uncompressed FVector. It you are not replicating the vector, FVector_NetQuantize behaves exactly the same as FVector. If compression to whole numbers is too extreme, there are also two other types available: FVector_NetQuantize10, which rounds to one decimal place (3 * 24 bits = 72 bits at most) and FVector_NetQuantize100, which rounds to two decimal places (3 * 30 bits = 90 bits at most). There is also FVector_NetQuantizeNormal which is meant for normalized vectors (which have a length of 1) and can therefore quite accurately represent the vector while only taking up 3 * 16 bits = 48 bits.
Hey Thanks @Grim. That answered my queries. Can you clarify some other things?
By whole number you mean Vector 1.1x + 2.1y + 3.1z will be converted to 1x + 2y + 3z before replicating?
Can you give examples for when should we use this FVector_NetQuantize? Because according to me this is just an insignificant improvement since a lot (really a lot) of properties are being replicated like movement, how can this little change bring such a high difference as stated by docs? So when should we exactly use this in multiplayer?
Yes that is exactly what is does. Just to be clear, the recipient will get the rounded version but locally the vector won’t change.
That depends on the specific situation. To put it into context, imagine we are replicating 10 FVectors from server to client with a frequency of 60 Hz. Worst case scenarious after 1 hour of gameplay:
No compression: 3 * 32bits * 10 * 60 * 3600 = 24.3 MB
With FVector_NetQuantize: 3 * 20 bits * 10 * 60 * 3600 = 16.2 MB
So we saved 8.1 MB of traffic. This could be a significant improvement if you are targeting a broad audience with your game. There will be people using bad w-lan connections while their 10 siblings are streaming youtube. For them this can make the difference between playable and un-playable, but for people with a 100 Mbps wire connection this won’t matter. Also, the unreal docs, while helpful more often than not, are not the holy grail of game development so don’t obsess over every sentence that doesn’t quite make sense to you.