Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Spectator mode

Discussion in 'NetCode for ECS' started by Ali_Bakkal, Mar 9, 2022.

  1. Ali_Bakkal

    Ali_Bakkal

    Joined:
    Jan 26, 2013
    Posts:
    84
    Hello Everyone,

    We want to implement a "spectator mode" in our game. Our multiplayer is working using ECS Netcode.
    And we want to give the possibility to customer to enter to watch (in live) game that is playing without affecting the performance of the server and of course without creating delay for user that are playing..

    How would you implement that ? (any suggestion or idea are welcome) :)
    @timjohansson @CMarastoni

    Best Regards,
    Ali
     
  2. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    Funny thing is I have implemented a spectator mode for my networked multiplayer game about 8 months ago. Some things to keep in mind:

    -Clients connecting as spectators still need to be "in game" just like clients connecting as players so they can receive ghost snapshots.

    -Client spectator entities should not be ghosts but rather entities that only exist on local clients so that they don't bog down the server or remote clients.

    -In most cases (and probably your case), you don't need to and shouldn't use the command stream to send input data from a spectator client to the server.

    -You can use different scenes for player and spectator setups. If you join a game as a player, load additively a "Player Join Settings" scene that references a PlayerJoinRpc prefab for instantiation. If you join a game as a spectator, instead load additively a "Spectator Join Settings" scene that references your spectator prefab for instantiation.
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,627
    It depends on your game and your requirements. If you have limited spectators simply making them connect to the game and receive ghost updates is fine.

    If you want your spectators to number say, 1000s then you need an alternate approach. The most obvious one is to simply have 1 spectator (server) join the game which spectators can connect to. This spectator server then simply forwards updates to all the spectators (how i believe games like dota work.) This way if you have an issue with the spectator server, bandwidth etc it doesn't affect the actual game.
     
    kBthrills likes this.
  4. Ali_Bakkal

    Ali_Bakkal

    Joined:
    Jan 26, 2013
    Posts:
    84
    Ok thank you for your answers but how can you connect to the game "to just receive ghost updates" ?
    Do you have any example code ? or which feature i should look to do that ?
     
  5. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
  6. Ali_Bakkal

    Ali_Bakkal

    Joined:
    Jan 26, 2013
    Posts:
    84
    I tried to implement the code, but it is not working.. can you share please the piece of code that are doing it please ?
    thanks in advance
     
  7. Ali_Bakkal

    Ali_Bakkal

    Joined:
    Jan 26, 2013
    Posts:
    84
    @TRS6123,

    Hello, i get back to you regarding the spectator mode,
    Can show me the piece of code that you use to connect to server as spectator mode please ?

    because i succeeded to connect with the server but i am not receiving any ghost object snapshots or updates ..