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 Jun 09, 2013 at 11:23 AM by Graham-Dunnett for the following reason:

Duplicate Question

avatar image
0
Question by AllenInch · Jun 09, 2013 at 01:18 AM · errorbuttonfps

"NullReferenceException: Object reference not set to an instance of an object" Error

I am getting a null reference exception error in my multiplayer FPS, when I am trying to send the character to a spawnpoint after pressing "spawn."

The code starts like this:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class MultiplayerManager : MonoBehaviour
 {

Then it calls the spawnpoints:

 public bool MatchLoaded;
     public MPPlayer MyPlayer;
     public GameObject[] Spawnpoint = new GameObject[4];
     
     void Start()
     {
         instance = this;
         PlayerName = PlayerPrefs.GetString("PlayerName");
         CurrentMap = MapList[0];
         DontDestroyOnLoad(gameObject);
     }

Then the server and client spawning systems:

 [RPC]
     void Server_SpawnPlayer(NetworkPlayer player)
     {
         int numberspawn = Random.Range(0, Spawnpoint.Length - 1);
         networkView.RPC("Client_SpawnPlayer", RPCMode.All, player, Spawnpoint[numberspawn].transform.position + new Vector3(0, 2, 0), Spawnpoint[numberspawn].transform.rotation);
     }
     
     [RPC]
     void Client_SpawnPlayer(NetworkPlayer player, Vector3 position, Quaternion rotation)
     {
         MultiplayerManager.GetMPPlayer(player).PlayerIsAlive = true;
         MultiplayerManager.GetMPPlayer(player).PlayerHealth = 100;
         if (player == MyPlayer.PlayerNetwork)
         {
             MyPlayer.PlayerManager.ControllerTransform.position = position;
             MyPlayer.PlayerManager.ControllerTransform.rotation = rotation;
             MyPlayer.PlayerManager.networkView.RPC("Client_PlayerAlive", RPCMode.All);
         }
         else
         {
             
         }
     }

and the actual button:

 void SpawnMenu()
     {
         if(GUI.Button(new Rect(5, Screen.height - 40, 250, 35), "Spawn"))
         {
             if (Network.isServer)
                 Server_SpawnPlayer(Network.player);
             else
                 networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player);
         }
     }

Thank you in advance for any and all help! This is a very frustrating issue. If you need more code (for reference) then ask and I will try to get back to you.

Comment
Comments Locked · Show 3
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 robertbu · Jun 09, 2013 at 01:24 AM 0
Share

Can you post the error message? What line is generating the error?

avatar image bodec · Jun 09, 2013 at 02:10 AM 0
Share

Sounds like he is instaniating a character to a spot that hasn't been created yet

avatar image Graham-Dunnett ♦♦ · Jun 09, 2013 at 11:23 AM 0
Share

There are lots of questions with answers telling you how to solve this.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Keep KGetting this error please help I dont know what to do 1 Answer

Why there is an 'SerializationException: serializationStream supports seeking, but its length is 0' error when I click the load button? 2 Answers

Button is not a member of GUI? 2 Answers

Spawning 2 players when the game starts 2 Answers

NullReferenceException 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