Hello Guest

Author Topic: Problem caching sprite IDs  (Read 5020 times)

Vartib

  • Newbie
  • *
  • Posts: 21
    • View Profile
Problem caching sprite IDs
« on: December 13, 2013, 12:42:46 am »
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:

Code: [Select]
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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem caching sprite IDs
« Reply #1 on: December 13, 2013, 11:01:51 am »
What does the parent tile game object contain?

Vartib

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Problem caching sprite IDs
« Reply #2 on: December 15, 2013, 04:19:05 am »
Sorry, should have included that in the original post. Here's a screenshot: http://i.imgur.com/b3pyZGK.png

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem caching sprite IDs
« Reply #3 on: December 15, 2013, 07:49:27 pm »
Thats quite weird, the sprite seems to have a null mesh filter. It shouldn't. Can you try to create a repro case and email support at unikronsoftware.com? That would make it a lot easier in tracking this down.

Vartib

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Problem caching sprite IDs
« Reply #4 on: December 17, 2013, 05:09:10 pm »
Don't have time to email it today, but I wanted to add that the Mesh Filter seems to change to "[none]" when I drag the tile from the Hierarchy to the project assets, which is where I normally store the parent tiles so they don't have to be in the scene directly. When I move it back to the Hierarchy it goes back to normal. Am I not supposed to store "parent" objects as assets like this?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem caching sprite IDs
« Reply #5 on: December 17, 2013, 09:42:10 pm »
No thats expected. Your screenshot didn't have any context in there so I had no idea what was going on.
I'm running out of things to suggest - can you create a repro case for this? If possible email it to support and I'll be happy to investigate this.

Vartib

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Problem caching sprite IDs
« Reply #6 on: December 29, 2013, 03:59:21 pm »
Just to be sure there's closer with this "issue," I wanted to update that this ended up being a problem with the user :D I'll spare you the details haha.

Thanks for your time!