PUN-instantiated 'Prefab' got destroyed by engine.
Options
When I use the following code:
public override void OnJoinedRoom() { Debug.Log("Joined a Room."); if (PhotonNetwork.IsMasterClient) { PhotonNetwork.LoadLevel(1); } PhotonNetwork.Instantiate(playerObject.name, new Vector3(0f, 5f, 0f), Quaternion.identity, 0); }The scene gets loaded but I get the following message:
PUN-instantiated 'Benz(Clone)' got destroyed by engine. This is OK when loading levels. Otherwise use: PhotonNetwork.Destroy().
0
Best Answer
-
Hi @swanishan,
Thank you for choosing Photon!
You need to wait until the level is loaded before doing the instantiation.
So maybe do that inside a script from the scene to be loaded.5
Answers
-
Hi @swanishan,
Thank you for choosing Photon!
You need to wait until the level is loaded before doing the instantiation.
So maybe do that inside a script from the scene to be loaded.5 -
Can you please tell me how to do that?
I googled and found answers for SceneManager.LoadScene But NOT for the PhotonNetwork.LoadLevel
Here is the code segment:public override void OnJoinedRoom() { Debug.Log("Joined a Room."); if (PhotonNetwork.IsMasterClient) { PhotonNetwork.LoadLevel(1); } PhotonNetwork.Instantiate(Obj.name, new Vector3(0f, 5f, 0f), Quaternion.identity, 0); }
I tried the following code but OnJoinedRoom doesn't call the LevelLoader...public override void OnJoinedRoom() { Debug.Log("Joined a Room."); if (PhotonNetwork.IsMasterClient) { LevelLoader(); } } IEnumerator LevelLoader() { PhotonNetwork.LoadLevel(1); while (PhotonNetwork.LevelLoadingProgress < 1) { yield return new WaitForEndOfFrame(); } PhotonNetwork.Instantiate(Obj.name, new Vector3(0f, 5f, 0f), Quaternion.identity, 0); }
0 -
0