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 /
avatar image
0
Question by Gabe_ · Aug 08, 2014 at 12:20 AM · instantiate

Null Reference Exception Error

I am getting the following error:

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

(wrapper stelemref) object:stelemref (object,intptr,object) Game.SpawnCharacter (Int32 ID, System.String Name, Int32 iX, Int32 iY, System.String Owner, Int32 MR) (at Assets/Game/Game.cs:130) Game.OnExtResponse (Sfs2X.Core.BaseEvent e) (at Assets/Game/Game.cs:123) I've triple checked everything relating to these segments of code and nothing seems to be un-instantiated. So I'm at a loss to what it can be. Here is the code: public TileData[,] Tile = new TileData[16, 16]; public TileData ActiveTile = new TileData(); public CharacterData[] Character = new CharacterData[25];
...
void OnExtResponse(BaseEvent e) { string cmd = (string)e.Params["cmd"]; ISFSObject ObjInput = (SFSObject)e.Params["params"];
if (cmd == "Start Match") { Debug.Log("Received Message"); for(int i = 0; i < ObjInput.GetInt("CharacterTotal"); i++) { Debug.Log("Spawning Character"); SpawnCharacter(i, (string)ObjInput.GetUtfStringArray("CharType").GetValue(i), (int)ObjInput.GetIntArray("xPos").GetValue(i), (int)ObjInput.GetIntArray("yPos").GetValue(i), (string)ObjInput.GetUtfStringArray("Owner").GetValue(i), (int)ObjInput.GetIntArray("MovementRange").GetValue(i)); //Error is here } UpdateChat(ObjInput.GetUtfString("TurnNotice")); } } void SpawnCharacter(int ID, string Name, int iX, int iY, string Owner, int MR) { Character[ID] = new CharacterData(); Character[ID].CharacterOBJ = new GameObject(); //Error occurs with our without this line Character[ID].CharacterOBJ = GameObject.Instantiate(Resources.Load(Name)) as GameObject; Character[ID].iX = iX; Character[ID].iY = iY; Character[ID].Owner = Owner; Character[ID].MovementRange = MR; Vector3 Pos = new Vector3((float)0.5 + iX, 0, (float)15.5 - iY); Character[ID].CharacterOBJ.transform.position = Pos; if(iY > 7) { Vector3 rot = new Vector3(0, 180, 0); Character[ID].CharacterOBJ.transform.Rotate(rot); } if(Character[ID].Owner == Username) { Character[ID].IsLocallyOwned = true; } if (Character[ID].Owner != Username) { Character[ID].IsLocallyOwned = false; }
Tile[iX, iY].IsOccupied = true; Tile[iX, iY].OccupierID = ID; }
Comment
Add comment · 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 · Aug 08, 2014 at 12:22 AM 0
Share

What line is generating the error. You are giving us a cut-down version of the class, so we cannot map the error to a specific line in the code.

avatar image Gabe_ · Aug 08, 2014 at 12:23 AM 0
Share

It is in there, the really long line that you need to scroll to see. It's Line 18 here

avatar image rutter · Aug 08, 2014 at 12:56 AM 0
Share

That is a very noisy line. Recommend breaking it down into several lines which you can analyze in the visual debugger.

Or, if you prefer the console print route:

 Debug.Log((string)ObjInput.GetUtfStringArray("CharType").GetValue(i));
 Debug.Log((int)ObjInput.GetIntArray("xPos").GetValue(i));
 Debug.Log((int)ObjInput.GetIntArray("yPos").GetValue(i));
 Debug.Log((string)ObjInput.GetUtfStringArray("Owner").GetValue(i));
 Debug.Log((int)ObjInput.GetIntArray("$$anonymous$$ovementRange").GetValue(i)));

If one of those lines errors out, you'll at least have a better idea of what went wrong.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Gabe_ · Aug 08, 2014 at 01:11 AM

I solved it myself, turns out having an empty GameObject, such as public TileData ActiveTile = new TileData(), caused the error...

Weird how it listed a seemingly arbitrary line for the error code.

Comment
Add comment · 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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Checking if object intersects? 1 Answer

Respawn Management 2 Answers

Problems instantiating a prefab (javascript) 1 Answer

Multiple Prefab Instantiation, Camera, Button and Scroll View Question 1 Answer

Raycast bullet impact and instantiating particles 3 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