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().

Best Answer

Answers

  • swanishan
    Options
    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);
    }
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @swanishan,

    Let's continue here.