PhotonNetwork.Instantiate issues when spawning after scene change.

Options
When I run PhotonNetwork.Instantiate, the created gameObject gets deleted after 1 update interval. When I put it on a slight wait timer the object spawns as usual. Is there a fix to this? Am I spawning my gameObject wrong?

if (Players == 1)
{
SceneManager.LoadScene("onlinefull");
PlayerClone = PhotonNetwork.Instantiate(PlayerPrefab.name, new Vector2(0f, 1.5f), Quaternion.identity);
if (PhotonNetwork.IsMasterClient)
{
photonView.RPC("MatchProgress", RpcTarget.All, false);
}
}

Thats what I have for when a player joins online mode when no other rooms could be found.

Comments

  • Hi @Vinny0,

    objects get destroyed on scene loading by default.

    In terms of PUN, when a client joins a room where other players have already instantiated their objects, he will receives these instantiation calls before the name of the scene he has to load. The result is, that the client will instantiate all objects and loads the scene afterwards, which ends in destroying those objects again.

    To avoid this, you can try to mark the player objects as DontDestroyOnLoad. Having this, they will 'survive' scene loading.