So I have a project with a ton of different buildings. When the player clicks a hotkey it spawns a general buildingMaster object with the specific building mesh and other data exposed at spawn. I pull the specifically requested mesh and building data from a Data table.
What I’m finding is that the buildingMaster object is replicating with blank values so I’d have to make additional network calls to get the mesh & info over to the client. There will be a lot of these buildings being built and destroyed.
I was trying to be clean and cute for scalability using the data table and 1 general building class.
It seems it would be smarter from a networking perspective to just have a class for every building with the default mesh & variables set to whatever is in the data table and scrap the DT.
Am I thinking of this the right way? What do the pros do?
Thanks for the reply. So the server is doing all of the work. I’m just finding that the expose on spawn variables aren’t replicating fast enough. So then I decided to do a rep notify for those variables which led me down this path - if I have to 1. replicate the building, then 2 rep notify the mesh change. Thats 2 network messages when I could just have a class that already has the mesh and values “hardcoded” and send only 1 message, the initial replication
Am i overthinking this? Is the network demand for this type of thing low and inconsequential?
RepNotify isn’t actually an additional network message (RPC), the actor spawning remotely isn’t happening immediately with the SpawnActor call. The Actor will only be added to the appropriate containers if it should replicate so that the next replication tick can process it. RepNotify typically (there are exceptions) just means that whenever the property value received via replication differs from the currently set value a function will be called locally.
So let me ask you this - Is there a way to make something replicate only if values change? Because I will only need these values to be replicated initially and then they can stay dormant until upgrades eventually come in. I guess I could just toggle replication off/on?
Is there significant bandwidth savings in doing it this way?
The server already compares a “shadow state” of the replicated properties (basically a copy of the last replicated state) and typically only replicates those that currently have a different value.
I remember having an issue where replicated Actors would be destroyed on clients due to no longer being relevant for the connection. So not sure if turning replication off entirely is actually going to work or whether that would also cause the actor to be destroyed on the client (I would expect that).
It’s nearly impossible to give any concrete values. That heavily depends on the project, the actors, how many properties are replicated and how often they are changed. As always with optimization it’s best to profile them in the actual project.
Unless you already know this is going to be a problematic bottleneck for your game you may not even need to worry about it yet (premature optimization) and look into optimizations once you get to the point where they are absolutely necessary.