Search Unity

Resolved Sync colors from server?

Discussion in 'Netcode for GameObjects' started by MatanYamin, Mar 6, 2023.

  1. MatanYamin

    MatanYamin

    Joined:
    Feb 2, 2022
    Posts:
    110
    Hi everyone, There is something I can't wrap my head about in NGO.

    I am instantiating and spawning from the server some GameObjects around the map (this works), and I want to change their color from the server and make it visible to all clients with that same color, without having the clients locally change the colors for each gameobject. Is there a way to do so?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,882
    Only if you despawn and spawn a new object with the desired color. Otherwise RPC message the color to clients and have them apply it to the material (or material property block).
     
  3. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    You should use a NetworkVariable for this. Keep in mind that you don't have control over what a client can do, so if a player alters the code of your game they can still overwrite the color locally (and they'll be the only ones who see the altered color.).

    I would not use an RPC as it won't sync the color when a client hot-joins a match.
     
    MatanYamin likes this.
  4. MatanYamin

    MatanYamin

    Joined:
    Feb 2, 2022
    Posts:
    110
    Thank you both.

    Thanks @RikuTheFuffs-U, I ended up using NetworkVariables and it seems to do the trick for my case!
    Solved.