Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Mirror - best approach with player objects across scenes

Discussion in 'Multiplayer' started by cerestorm, Jun 18, 2021.

  1. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    656
    I'm looking for advice on the best approach for what I'm trying to achieve.

    I have an online scene where connected players select the side they wish to control and this is stored in the Player object. When selections are complete the game is switched to the Game scene using ServerChangeScene. This is where the problems begin.

    The Player objects are destroyed and recreated by Mirror and so lose their side values. I did get around this by setting them as DontDestroyOnLoad but I'm not sure this is such a good idea for the Player object that Mirror spawns from the PlayerPrefab, plus I was getting an error latterly which I thought was related to that.

    So instead currently the server saves the selection data and re-adds it back to the Players once they have been spawned on the Game scene. This leads to another issue I need advice on; what's the best way to inform the client that a spawned object is ready for use. Currently I need to make some sort of callback to let the scene know that the players are ready and their side values are set so I can create computer players for sides not selected by human players.

    Any advice much appreciated.
     
  2. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Check out our examples, some of them do scene changing.
    If in doubt, join our Discord and ask MrGadget, he's the scene guy :)
     
    cerestorm likes this.