• 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 /
avatar image
Question by joeybubble1 · Oct 04, 2012 at 06:17 PM · errormeshfpsnullreferenceexeption

NullReferenceException

Hey everyone, recently I have been getting these two Errors and I don't know how to solve them,

 ArgumentOutOfRangeException: Argument is out of range.
 Parameter name: index
 System.Collections.Generic.List`1[UnityEngine.Mesh].get_Item (Int32 index) (at /Applications/buildAgent/work/3df08680c6f85295/mcs/class/corlib/System.Collections.Generic/List.cs:633)
 Main.BuildData ()
 Main.OnEnable ()
 UnityEngine.Network:Instantiate(Object, Vector3, Quaternion, Int32)
 MultiplayerManager:ClientAddPlayerToList(String, NetworkPlayer) (at Assets/Scripts/MultiplayerManager.cs:83)
 UnityEngine.NetworkView:RPC(String, RPCMode, Object[])
 MultiplayerManager:ServerPlayerJoinRequest(String, NetworkPlayer) (at Assets/Scripts/MultiplayerManager.cs:68)
 MultiplayerManager:OnServerInitialized() (at Assets/Scripts/MultiplayerManager.cs:44)
 UnityEngine.Network:InitializeServer(Int32, Int32, Boolean)
 MultiplayerManager:StartServer(String, String, Int32) (at Assets/Scripts/MultiplayerManager.cs:38)
 MenuManager:Main_Host() (at Assets/Scripts/MenuManager.cs:94)
 MenuManager:OnGUI() (at Assets/Scripts/MenuManager.cs:33) 

and

 NullReferenceException
 UnityEngine.Mesh.get_bounds () (at C:/BuildAgent/work/a0f11f3559d72c6d/Runtime/ExportGenerated/Editor/Grap$$anonymous$$cs.cs:971)
 Main.BuildData ()
 Main.OnEnable ()
 UnityEngine.Network:Instantiate(Object, Vector3, Quaternion, Int32)
 MultiplayerManager:ClientAddPlayerToList(String, NetworkPlayer) (at Assets/Scripts/MultiplayerManager.cs:83)
 UnityEngine.NetworkView:RPC(String, RPCMode, Object[])
 MultiplayerManager:ServerPlayerJoinRequest(String, NetworkPlayer) (at Assets/Scripts/MultiplayerManager.cs:68)
 MultiplayerManager:OnServerInitialized() (at Assets/Scripts/MultiplayerManager.cs:44)
 UnityEngine.Network:InitializeServer(Int32, Int32, Boolean)
 MultiplayerManager:StartServer(String, String, Int32) (at Assets/Scripts/MultiplayerManager.cs:38)
 MenuManager:Main_Host() (at Assets/Scripts/MenuManager.cs:94)
 MenuManager:OnGUI() (at Assets/Scripts/MenuManager.cs:33)

Here is the code that contains the instantiate command mentioned in the error.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class MultiplayerManager : MonoBehaviour
 {
     public static MultiplayerManager instance;
     public string PlayerName;
     private string MatchName = "";
     private int MaxUsers = 32;
     private string MatchPassword = "";
     public int altprefix;
     public bool MatchStarted = false;
     public bool MatchedLoaded = false;
     
     public List<MpPlayer> PlayerList = new List<MpPlayer>();
     public List<RoomSettings> RoomSettings = new List<RoomSettings>();
     
     public RoomSettings Settings = null;
     
     public MpPlayer MyPlayer;
     public GameObject[] SpawnPoints;
     
     public GameObject PlayerManagerPrefab;
             
     void Start(){
         Application.targetFrameRate = 60;
         instance = t$$anonymous$$s;
         PlayerName = PlayerPrefs.GetString("PlayerName");
         Settings = RoomSettings[0];
         DontDestroyOnLoad(gameObject);
     }
     
     public void StartServer(string Name, string Password, int MaxPlayers){
         MatchName = Name;
         MatchPassword = Password;
         MaxUsers = MaxPlayers;
         Network.InitializeServer(MaxPlayers,2550,true);
         MasterServer.RegisterHost("TDM",MatchName,"Comment");
         //Network.InitializeSecurity();
     }
     
     void OnServerInitialized(){
         ServerPlayerJoinRequest(PlayerName,Network.player);    
     }
     
     void OnConnectedToServer(){
         networkView.RPC("ServerPlayerJoinRequest",RPCMode.Server,PlayerName,Network.player);
     }
     
     void OnPlayerConnected(NetworkPlayer player) {
         foreach(MpPlayer pl in PlayerList){
             networkView.RPC("ClientAddPlayerToList",player,pl.PlayerName,pl.PlayerNetwork);    
         }
         networkView.RPC("Client_GetMatchSettings",player,Settings.MapLoadName,"","");    
     }
     
     void OnPlayerDisconnected(NetworkPlayer id){
         networkView.RPC("RemovePlayerToList",RPCMode.All,id);    
     }
     
     void OnDisconnectedFromServer(NetworkDisconnection info) {
         PlayerList.Clear();    
     }
     
     [RPC]
     void ServerPlayerJoinRequest(string PlayerName, NetworkPlayer View){
         networkView.RPC("ClientAddPlayerToList",RPCMode.All,PlayerName,View);
     }
     
     [RPC]
     void ClientAddPlayerToList(string PlayerName, NetworkPlayer View){
         
         
         if(Network.player == View){
             MpPlayer tempPlayer = new MpPlayer();
             MyPlayer = tempPlayer;
             
             tempPlayer.PlayerName = PlayerName;
             tempPlayer.PlayerNetwork = View;
             
             //GameObject Player = 
             GameObject Player = Network.Instantiate(PlayerManagerPrefab,Vector3.zero,Quaternion.identity,0) as GameObject;
             
             Player.GetComponent<PlayerManager>().t$$anonymous$$sPlayer = MyPlayer;
             
             PlayerList.Add(tempPlayer);
         }
     }
     
     [RPC]
     void RemovePlayerToList(NetworkPlayer View){
         MpPlayer temp = new MpPlayer();
         foreach(MpPlayer pl in PlayerList){
             if(pl.PlayerNetwork == View){
                 temp = pl;    
             }
                 
         }
         if(temp != null){
             PlayerList.Remove(temp);
             Network.Destroy(temp.PlayerManager.gameObject);
         }
             
     }
     
     [RPC]
     void Client_GetMatchSettings(string map, string mode,string others){
         Settings = GetMap(map);
     }
     
     public RoomSettings GetMap(string name){
         RoomSettings get = null;
         
         foreach(RoomSettings rs in RoomSettings){
             if(rs.MapLoadName == name){
                 get = rs;
                 break;
             }
         }
         
         return get;
     }
     
     [RPC]
     void Client_LoadMap(string map, int prefix){
         //Network.SetLevelPrefix(prefix);
         Application.LoadLevel(map);
     }
     
     void OnGUI(){
         if(!MyPlayer.PlayerIsAlive && MatchedLoaded)
             SpawnMenu();
         if(MyPlayer.PlayerIsAlive){
             if(GUILayout.Button("Suicide"))
                 MyPlayer.PlayerManager.HandleBulletDamage(100);
         }
         
     }
     
     [RPC]
     void Server_SpawnPlayer(NetworkPlayer Player){
         int numberSpawn = Random.Range(0,SpawnPoints.Length);
         networkView.RPC("Client_SpawnPlayer",RPCMode.All,Player,SpawnPoints[numberSpawn].transform.position,SpawnPoints[numberSpawn].transform.rotation);    
     }
     [RPC]
     void Client_SpawnPlayer(NetworkPlayer Player, Vector3 Pos, Quaternion Rot){
         MultiplayerManager.GetMPPlayer(Player).PlayerIsAlive = true;
         if(Player == MyPlayer.PlayerNetwork){
             MyPlayer.PlayerManager.ControllerTranform.position = Pos;
             MyPlayer.PlayerManager.ControllerTranform.rotation = Rot;
             MyPlayer.PlayerManager.networkView.RPC("Client_ImAlive",RPCMode.All);
     //    }else{
                 
         }
     }
     
     void OnLevelWasLoaded(){
         MatchedLoaded = true;
         if(Application.loadedLevelName == Settings.MapName && Network.isServer){
             SpawnPoints = GameObject.FindGameObjectsWithTag("SpawnPoint");    
             networkView.RPC("Client_ServerLoaded",RPCMode.AllBuffered);
         }
     }    
     
     [RPC]
     void Client_ServerLoaded(){
         MatchStarted = true;    
     }
     
     public static MpPlayer GetMPPlayer(NetworkPlayer Player){
         foreach(MpPlayer pl in MultiplayerManager.instance.PlayerList){
             if(pl.PlayerNetwork == Player)
                 return pl;
         }
         return null;
     }
     
     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);    
             }
         }
     
 }
 [System.Serializable]
 public class MpPlayer {
     public string PlayerName = "";
     public NetworkPlayer PlayerNetwork;
     public PlayerManager PlayerManager;
     public int PlayerHealth = 100;
     public bool PlayerIsAlive;
     public int PlayerKills;
     public int PlayerDeaths;
 }
 [System.Serializable]
 public class RoomSettings{
     public string MapName;
     public string MapLoadName;
     
 }
 
Comment

People who like this

0 Show 5
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 gregzo · Oct 04, 2012 at 06:23 PM 0
Share

which line is giving you the error? Double click on the error in the console, it'll take you straight to it.

avatar image joeybubble1 · Oct 04, 2012 at 06:36 PM 0
Share

Its the Instantiate in "ClientAddPlayerToList"

avatar image gregzo · Oct 04, 2012 at 06:46 PM 0
Share

I'd have to dig deeper, but at first read I would advise you to follow convention and not name variables with a capital. A lot in your naming is confusing : NetworkPlayer PlayerNetwork??? Why not NetworkPlayer nPl, or networkPlayer, or netPlayer, whatever but stick with it.

Worst, in your class declaration for MpPlayer, PlayerManager PlayerManager - naming a var the same as it's class is asking for trouble.

The only thing in a class declaration which SHOULD have the same name as the class is it's constructor.

avatar image joeybubble1 · Oct 04, 2012 at 06:53 PM 0
Share

Never mind, sorry for wasting your time, but I fixed it, for some reason loads of the mesh objects in the playerobject had scripts attached to them, and apparently I deleted the script that was attached and was causing me those errors.. But I'll keep the advice you gave me in mind :D Thank you!!!!!!!!!!!!!!

avatar image gregzo · Oct 04, 2012 at 06:59 PM 0
Share

Can you reply and accept your own answer then? Helps keeping things tidy (your question wont be marked as unanswered anymore).

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by joeybubble1 · Oct 04, 2012 at 07:01 PM

Never Mind People!

Comment

People who like this

0 Show 0 · Share
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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Multiple Cars not working 1 Answer

error CS1061 anybody might help me? 1 Answer

NullReferenceExeption 1 Answer

combining children error 2 Answers

MeshCombineUtility -1 Answers


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