Hello Guest

Author Topic: tk2dSprite.SetSprite(newCollection, Sprite)  (Read 3972 times)

djip123

  • Newbie
  • *
  • Posts: 3
    • View Profile
tk2dSprite.SetSprite(newCollection, Sprite)
« on: October 31, 2013, 10:49:08 am »
Hey. I got some code that i think is right, but it gives a error: NullReferenceException: Object reference is not set to an instance of an object.
I have dragged the Datacollection into the script. But i guess there could be a issue there ?
Code: [Select]
public tk2dSpriteCollectionData CD;
public int i;

public List<GameObject> Servers = new List<GameObject>();

private RoomInfo[] oldList;
void Awake () {

}

// Update is called once per frame
void Update () {
if (oldList != PhotonNetwork.GetRoomList()){

// foreach(tk2dSprite obj in this.gameObject.GetComponentsInChildren<tk2dSprite>()){
// GameObject.Destroy(obj.gameObject);
// }

i = 0;

foreach (RoomInfo game in PhotonNetwork.GetRoomList()){
int spriteID = CD.GetSpriteIdByName("infoBox");
// GameObject tempObj = new GameObject("Server "+i.ToString());
GameObject obj = new GameObject();
tk2dSprite.AddComponent(obj, CD, spriteID);
// tk2dSprite tempSpr = tempObj.AddComponent<tk2dSprite>();
// tempSpr.SetSprite(CD,CD.);
// tempObj.GetComponent<tk2dSprite>().SetSprite
// tempObj.transform.position = new Vector3(0,0,-0.1f);

// this.gameObject.AddChild(tempObj.transform);
//Servers.Add(tempObj);
i++;

Debug.Log("Server Added");
}

oldList = PhotonNetwork.GetRoomList();

Debug.Log("GameList Updated");
}
}

Please check if something is wrong ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSprite.SetSprite(newCollection, Sprite)
« Reply #1 on: October 31, 2013, 12:27:47 pm »
Which line is triggering the error?
And what are CD and spriteID? Can you debug.log them?

djip123

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: tk2dSprite.SetSprite(newCollection, Sprite)
« Reply #2 on: October 31, 2013, 12:38:23 pm »
This line gives Error:
int spriteID = CD.GetSpriteIdByName("infoBox");

And CD returns null, but i don't really understand since i have dragged it in the script, and it seems ok.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSprite.SetSprite(newCollection, Sprite)
« Reply #3 on: October 31, 2013, 12:46:30 pm »
I'm not sure why CD would be null, have you tried debugging this?

djip123

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: tk2dSprite.SetSprite(newCollection, Sprite)
« Reply #4 on: October 31, 2013, 01:01:01 pm »
Wow, so sad, the script was attached to another Gameobject on the scene! Ok my bad ^_^

But anyway thanks for the fast reply, maybe i will need it later, keep up the good work with 2D ToolKit!