The current script I'm working on is going to be used to swap out sprites for my terrain objects during runtime, but I've run into a problem with retrieving the sprite IDs. My goal is to have a single script do the swapping for all of my terrain objects so I don't have to have a script attached to each of them individually. From what I've read in the documentation it should be as easy as doing the following:
public GameObject ParentTile;
private tk2dSprite sprite;
private int spriteID;
sprite = ParentTile.GetComponent<tk2dSprite>();
spriteID = sprite.GetSpriteIdByName("RoomFloor0");
ParentTile is an object I add to the script in the editor that has a sprite with the correct sprite collection selected. Everything looks like it should work, but when I run the program I get the following error at the line with "spriteID = ..."
"NullReferenceException: Object reference not set to an instance of an object."
It seems like whatever is getting saved as "sprite" isn't what the program wants, but I'm at a loss as to what it's looking for.