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;
}