Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Sep 14, 2014 at 08:38 PM by Graham-Dunnett for the following reason:

Duplicate Question

avatar image
-1
Question by TheBlackBox · Sep 14, 2014 at 08:37 PM · nullreferenceexception

Object Reference Not Set To An Instance Of An Object!

Hey! I've been trying to get a simple UFPS player to work over a Photon Network. I came across this error:-

NullReferenceException: Object reference not set to an instance of an object NetworkManager.SpawnMyPlayer () (at Assets/NetworkManager.cs:47) NetworkManager.OnJoinedRoom () (at Assets/NetworkManager.cs:35) UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions) NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[]) (at Assets/_Imported/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1769) NetworkingPeer:OnEvent(EventData) (at Assets/_Imported/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1612) 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:76)

In my script I referenced a component on my UFPS Player GO "Vp_FPController" Here is the script :-

 using UnityEngine;
 using System.Collections;
 
 public class NetworkManager : MonoBehaviour {
     
     SpawnSpot[] spawnSpots;
 
     // Use this for initialization
     void Start () {
         spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
         Connect ();
     }
 
     void Connect() {
         PhotonNetwork.ConnectUsingSettings( "FPS Game 0.00004" );
     }
      
     void OnGUI() {
         GUILayout.Label( PhotonNetwork.connectionStateDetailed.ToString() );
     }
 
     void OnJoinedLobby() {
         Debug.Log ("OnJoinedLobby");
         PhotonNetwork.JoinRandomRoom();
     }
 
     void OnPhotonRandomJoinFailed() {
         Debug.Log ("OnPhotonRandomJoinFailed");
         PhotonNetwork.CreateRoom( null );
     }
 
     void OnJoinedRoom() {
         Debug.Log ("OnJoinedRoom");
 
         SpawnMyPlayer();
     }
 
     void SpawnMyPlayer() {
         if(spawnSpots == null) {
             Debug.LogError ("NO SPAWN POINTS FOUND!!!");
             return;
         }
 
         SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, spawnSpots.Length) ];
         GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("SimplePlayer", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
 
         ((MonoBehaviour)myPlayerGO.GetComponent("Vp_FPController")).enabled = true;
         ((MonoBehaviour)myPlayerGO.GetComponent("Vp_FPinput")).enabled = true;
     }
 }

I'm not sure why the GameObject isn't being referenced as I am in the script clearly asking to enable it (The script is supposed to enable the component once the player spawns into the game.)

I have disabled the component, could this be why? I've tryed it with the component activated but that doesn't do what I want it to do...

If you guys need to know anything else please be sure to ask and I'll provide.

Comment
Comments Locked · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Graham-Dunnett ♦♦ · Sep 14, 2014 at 08:38 PM 1
Share

I re-tagged your question so it links to the 50 pages of questions about null reference exceptions.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

NullReferenceException problem 2 Answers

NullReferenceException: I think unity bug 3 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Scripting error comes up when I press play 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges