Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Im getting a "NullReferenceException: Object reference not set to an instance of an object" error not sure why.

$
0
0
I'm following quill18creates's tutorial on making a Multiplayer FPS and I'm on part 5 of his tutorial. I get this error: NullReferenceException: Object reference not set to an instance of an object NetworkManager.SpawnMyPlayer () (at Assets/NetworkManager.cs:45) NetworkManager.OnJoinedRoom () (at Assets/NetworkManager.cs:36) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[]) (at Assets/_Imported/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1955) NetworkingPeer:OnEvent(EventData) (at Assets/_Imported/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1791) ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[]) ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands() ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() PhotonHandler:Update() (at Assets/_Imported/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:83) And this is my code: using UnityEngine; using System.Collections; public class NetworkManager : MonoBehaviour { public Camera standbyCamera; SpawnSpot[] spawnSpots; // Use this for initialization void Start () { spawnSpots = GameObject.FindObjectsOfType (); Connect (); } void Connect () { PhotonNetwork.ConnectUsingSettings ("v1.0.0"); } void OnGUI() { GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString() ); } void OnJoinedLobby() { Debug.Log ("Joined Lobby"); PhotonNetwork.JoinRandomRoom (); } void OnPhotonRandomJoinFailed() { Debug.Log ("Failed To Join Room"); PhotonNetwork.CreateRoom (null); } void OnJoinedRoom() { Debug.Log ("Joined Room"); SpawnMyPlayer (); } void SpawnMyPlayer() { SpawnSpot mySpawnSpot = spawnSpots [Random.Range (0, spawnSpots.Length)]; GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0); standbyCamera.enabled = false; ((MonoBehaviour)myPlayerGO.GetComponent("FPSInputController")).enabled = true; ((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true; myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true); } } Not sure where im going wrong, it's my first time using C#.

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>