I am not able to see other players

Options

Hi,

I have a multiplayer game with different scenes. All players are instantiated using one script - and they are instantiated in the "Game" scene. Initially, they are able to see each other. But when one player leaves a scene, goes to another, and comes back to the "Game" scene, that player is not able to see others. But others are able to see that player. What is going wrong here? This is the script used to instantiate players:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class SpawnPlayers : MonoBehaviourPunCallbacks
{
    public GameObject playerPrefab;

    private GameObject playerObject;

    private void Start()
    {
        if (playerObject == null)
        {
            Vector3 randomPosition = new Vector3(0f, 0f, -8f);
            playerPrefab.transform.rotation = Quaternion.Euler(0f, 0f, 0f);

            playerObject = PhotonNetwork.Instantiate("Bork", randomPosition, playerPrefab.transform.rotation);
        }
    }

    private void OnDestroy()
    {
        if (playerObject != null)
        {
            Debug.Log("destroyed");
            PhotonNetwork.Destroy(playerObject);
        }
    }
}


Answers

  • Tobias
    Options

    I assume you load the other scene exclusively?! That means it destroys all GOs there are. This also destroys all networked objects and going back to the other scene doesn't bring them back.

    Networking wise, loading a scene doesn't do anything specific. It just adds more objects in the scene one client sees. So make sure to either use DontDestroyOnLoad() for the networked objects or load scenes additive.