Why is my network player spawner stop working when I switch scenes? SOLVED

Options

I am on the free version of pun and I am on the newest version. When I switch scenes it gives me this error NullReferenceException: Object reference not set to an instance of an object NetworkPlayerSpawner.Update () (at Assets/Photon stuff/Scripts/NetworkPlayerSpawner.cs:26) also if i make it try to join room over and over again it joins the room! using System.Collections;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Photon.Pun;


public class NetworkPlayerSpawner : MonoBehaviourPunCallbacks

{

  public GameObject spawnedPlayerPrefab;


  public Transform rigHead;

  public Transform rigLeftHand;

  public Transform rigRightHand;


  private Transform head;

  private Transform leftHand;

  private Transform rightHand;


  private Transform mIK;


  private new PhotonView photonView;


  public bool isPlayerSpwaned = false;


  void Update()

  {

    // Checks if we are in a room before trying to work with our Network Player

    if (PhotonNetwork.InRoom == true)

      if (photonView.IsMine)

      {

        // If this is our avatar then make it not viewable to the player and set the positions of our Gorilla Rig to our Network Player

        //head.gameObject.SetActive(true);

        //leftHand.gameObject.SetActive(false);

        //rightHand.gameObject.SetActive(false);

        //mIK.gameObject.SetActive(false);


        MapPosition(head, rigHead);

        MapPosition(leftHand, rigLeftHand);

        MapPosition(rightHand, rigRightHand);

      }

  }


  void MapPosition(Transform target, Transform rigTarget)

  {

    // Changes position and rotation of specified transforms


    target.position = rigTarget.position;

    target.rotation = rigTarget.rotation;

  }


  public override void OnJoinedRoom()

  {

    // When we join a room it adds a new Network Player

    base.OnJoinedRoom();

    spawnedPlayerPrefab = PhotonNetwork.Instantiate("Network Player", transform.position, transform.rotation);


    // Get our Photon View and other things

    photonView = spawnedPlayerPrefab.GetComponent<PhotonView>();


    head = spawnedPlayerPrefab.transform.Find("Head");

    leftHand = spawnedPlayerPrefab.transform.Find("Left Hand");

    rightHand = spawnedPlayerPrefab.transform.Find("Right Hand");


    isPlayerSpwaned = true;


    //mIK = spawnedPlayerPrefab.transform.Find("ybot");

  }


  public override void OnLeftRoom()

  {

    // When we leave a room it removes our Network Player

    base.OnLeftRoom();

    PhotonNetwork.Destroy(spawnedPlayerPrefab);

  }

}

Why is this happening please help SOLVED!!

Answers

  • chair
    Options

    I found that this error is causing the null [NetworkVoice.PhotonVoiceNetwork] 2022-07-23T00:44:11:An instance of PhotonVoiceNetwork is already set. Destroying extra instance.

    UnityEngine.Debug:LogErrorFormat (UnityEngine.Object,string,object[])

    Photon.Voice.Unity.VoiceLogger:LogError (string,object[]) (at Assets/Photon stuff/Photon/PhotonVoice/Code/VoiceLogger.cs:67)

    Photon.Voice.PUN.PhotonVoiceNetwork:set_Instance (Photon.Voice.PUN.PhotonVoiceNetwork) (at Assets/Photon stuff/Photon/PhotonVoice/Code/PUN/PhotonVoiceNetwork.cs:151)

    Photon.Voice.PUN.PhotonVoiceNetwork:Awake () (at Assets/Photon stuff/Photon/PhotonVoice/Code/PUN/PhotonVoiceNetwork.cs:240)

  • chair
    Options

    How do I fix this error?

  • chair
    Options

    Actually this warning is causing a null ConnectUsingSettings() failed. Can only connect while in state 'Disconnected'. Current state: Connected

    UnityEngine.Debug:LogWarning (object)

    Photon.Pun.PhotonNetwork:ConnectUsingSettings (Photon.Realtime.AppSettings,bool) (at Assets/Photon stuff/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1137)

    Photon.Pun.PhotonNetwork:ConnectUsingSettings () (at Assets/Photon stuff/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:1130)

    NetworkManager:ConnectToServer () (at Assets/Photon stuff/Scripts/NetworkManager.cs:18)

    NetworkManager:Start () (at Assets/Photon stuff/Scripts/NetworkManager.cs:12)