UE automatically handles client prediction for character movement (which is nice) but I cannot figure out how to do prediction efficiently for other variables.
For example, I have an array of items (player’s inventory) that I want to replicate. If I mark it with
DOREPLIFETIME and only do logic on the server, the player is going to experience delay when interacting with his inventory because the client must wait for server to send the changes back.
My first solution was to do logic on client anyway and then overwrite the results in
OnRep_ function. This solution works but it doesn’t seem efficient because the client is going to calculate correctly most of the time and the server’s result are redundant.
My second solution to address this issue was to first do the logic on client, create a hash from the end state, and send the hash alongside the input to the server. Then the server can know if the need to send a correction to the client or not.
For example, if player wants to consume an item, I consume the item locally, calculate a hash of player’s inventory, and send the consume request alongside the hash to the server. Then server does the logic, and creates a hash from the end state of the inventory. If the hashes match, then it doesn’t need to send back the inventory to the player.
The first solution saves processing power but consumes more bandwidth. The second solution saves bandwidth but requires more processing power.
Is there any other solution to this or I’m forced to choose between these two?