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 PUN2 instantiate new players into scene 2 instead of scene 1

Discussion in 'Multiplayer' started by lxgee, Jun 20, 2021.

  1. lxgee

    lxgee

    Joined:
    Jun 3, 2021
    Posts:
    12
    Hi guys,

    noob question. I have 3 scenes: menu, lobby and game. Currently players can join the lobby through the menu fine, and when the game starts everyone gets instantiated into the game fine.

    What I'm not sure about, is how do make it so that once the game has started (everyone is now in game scene), any NEW players who join get instantiated into the game scene and skip the lobby scene.

    I have PhotonNetwork.AutomaticallySyncScene = true; in both my lobby and game scenes. While testing, when I try to join after the lobby scene is "over", I remain on the menu scene, although the OnJoinedRoom() function is called, but nothing happens.

    hope that makes sense.

    Thanks!
     
  2. lxgee

    lxgee

    Joined:
    Jun 3, 2021
    Posts:
    12
    Ok my bad the room was set to closed. Now my "late joiner" is being instantiated into the game scene, but the player can't move (which I assume is an issue with the player controller script which normally connects their movement to a joystick prefab. And I'm getting this error over and over in the console: MissingReferenceException: The object of type 'Rigidbody2D' has been destroyed but you are still trying to access it.

    The error is linked to a line in my player controller and a line in my game controller which normally alter the rigidbody. the rigidbody2d is attached tot he playercontroller script thorugh the inspector so i assumed it should be linked with the newly instantiated player. Anyone know why I might be having these issues? When I test in the game scene, the joystick and rigidbody seem to be linked to the playercontroller script Oo.
     
  3. lxgee

    lxgee

    Joined:
    Jun 3, 2021
    Posts:
    12
    Alright so I resolved the issues above by changing my game to prevent my players being destroyed on scene change. Now I can have players join the correct scene even if they're late. but this has created a new problem which I'm even more stuck on:
    When a player leaves and then returns it creates duplicates of the existing players as described above. I tried to use IsMine but my players are instantiated in lobby/game controller which by default is owned by the master so I can't use IsMine. hmm