The correct way to replicate a building

Hi,

I am a bit puzzled and would just like some feedback on witch method is correct.
my character can place a building and this replicates the placed building across the network. after executing on the server

now my question: if the building is already replicated what would be the best method for the following (both work).

Building one is a battery (collects power- has variable (currentpower and maxpower))
Building 2 is a generator it stores +1 power every second into the battery.

Method 1: no additional replication the generator is running the +1 power every event tick. and stores it successfully.

Method 2: generator calls an event on the battery to increase storage by +1 every second, this runs on the server and replicates to clients (using replicated variables (currentpower and maxpower)).

what would be considered the correct approach?
as it feels like i am replicating twice: first when built and then on updates, but my understanding of networking is still a bit unclear hence the question

Thank you :slight_smile:

spawn a building on server, call multicast to spawn on clients.

add +1 power on a timer in both client and server machines, (No replication)

when power fills up or gets used, do that on the server, and multicast to clients. if power fills up on client, stop adding +1 to power, but don’t trigger any “fully powered” events until the server version is filled.

so the server does all the important stuff, but the client adds their own power over time, just as a visual effect that estimates what is going on in the server. when an actor does this kind of client side estimation, it is known as a simulated proxy.

1 timer on the battery, adding up all connected generator’s charging rates, seems to be an efficient method to reduce function call overhead and simplify communication.

Thank you that gave me a lot more clarity,

just one more question if I may.

The timer would that be located on each generator ? and send a message to the battery ( I can have multiple generators to increase the amount). or should i rather have 1 timer on the battery that adds the accumulated amount every second ?

I appreciate the push in the right direction :slight_smile:

I have it set up as the timer executing the add or subtract every second and every building makes one call to change the value (runs on server )

basically i changed it to how you explained :slight_smile: thanks

although if I do not replicate the variable (current Power) it doesnt show on client

I have a authority check before changes and a replicate to updates