Updating state of multiple instances of class

its unclear to me how to address a pretty basic use case in UNet. Say I have a Ship class and there are multiple instances of it in a networked game and each has a health property. At some point one of them gets damaged and I need to update the health of that instance on all the clients. As far as I can tell my options are:

  • ClientRpc: I could call an rpc with the updated health but then every ship will update their health.
  • SyncVar: As far as I can tell this is the same as ClientRpc and would update all the ships in the game.
  • TargetRpc: this would update all the instances on one client but that still is not useful.

Am I misunderstanding how these work? Is there some other mechanism that allows you to synchronize state on a specific instance (short of writing individual message types for each)?

You’re misunderstanding a bit, or you’re not being very clear what you want.

So lets say in your game you have a dozen ships all flying around shooting each other. All of them have NetworkIdentity components and are instantiated/spawned using the same prefab.

So a single ship takes damage. On the server you update either a SyncVar or call a ClientRpc with the new health value for that ship. On all clients just that single ship gets updated with the new health value. It doesn’t matter that all of the other ships are from the same prefab and have the same script component you used to update the SyncVar or call the ClientRpc from. SyncVars, ClientRpcs, and TargetRpcs all get directed to the same instance of that gameobject as they were called on by the server. This is done through an ID associated with the NetworkIdentity component.