Can not Instantiate before the client joined/created a room. State: PeerCreated

Hi all! I got an error when creating a shooter, yes, I'm between junior and middle (the name is the error) here is the code:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Photon.Pun;


public class SpawnManager : MonoBehaviourPunCallbacks

{

  public GameObject[] redSpawn;

  public GameObject[] blueSpawn;


  public GameObject Player;


  void Update()

  {

    Awake();

  }


  private void Awake()

  {

    if (Choice.redChoice == true)

    {

      Vector3 randomRedPosition = redSpawn[Random.Range(0, redSpawn.Length)].transform.localPosition;


      PhotonNetwork.Instantiate(Player.name, randomRedPosition, Quaternion.identity);

    }


    if (Choice.blueChoice == true)

    {

      Vector3 randomBluePosition = blueSpawn[Random.Range(0, blueSpawn.Length)].transform.localPosition;


      PhotonNetwork.Instantiate(Player.name, randomBluePosition, Quaternion.identity);

    }

  }

}


The problem is here: PhotonNetwork.Instantiate(Player.name, randomRedPosition, Quaternion.identity); and PhotonNetwork.Instantiate(Player.name, randomBluePosition, Quaternion.identity);


Help please in the forums did not find now I sit and think

Answers

  • It sounds a lot as if you guesstimate your way into using PUN. This is likely to fail and cost you time. Even more if you have to wait.

    The error basically tells you: Before you network instantiate objects, go online, find a match.

    Do the PUN Basics Tutorial and code it.