Hello Guest

Author Topic: [URGENT] WTF Sprite being destroyed when visible?  (Read 4909 times)

CoderBear

  • Newbie
  • *
  • Posts: 13
    • View Profile
[URGENT] WTF Sprite being destroyed when visible?
« on: May 22, 2013, 10:56:28 pm »
Ok so this happened today within about a couple of hours prior to this post.  I have a sprite that is kept invisible until an effect makes it visible (NGUI 11).  When the game runs all seems to be well (NGUI 12).  BUt you press the button with a shield and S on it and suddenly...
the object may appear for a split second and then immediately disappear and gets detroyed (NGUI 13).  My question is why is this happening and why is this the only sprite affected.

Unity: 4.1.2f
2Dtk: 1.92 + Patch 1

Before you go accusing me of destroying.  this is the only piece of code "I wrote" that touches the sprite.  Please note that sprite is the Shield Sprite, and icon is the Button Sprite.

The weird thing is this just happened randomly.

Code: [Select]
public void clickedFA ()
{
// tracker.AddProgressToAchievement ("Shielded", 1.0f);
// StoreInventory.TakeItem (itemId, 1);

// balance = StoreInventory.GetItemBalance (itemId);
balance--;
textMesh.text = balance.ToString ();
textMesh.Commit ();

icon.color = Color.gray;
cooldownActive = !cooldownActive;

Invoke("ResetIcon", 5);  // cooldown in 5 seconds.
ActivateShield();
}

private void ActivateShield() {
sprite.gameObject.SetActive(true);
Invoke("DectivateShield", 3); // last 3 seconds
}

private void DectivateShield() {
sprite.gameObject.SetActive(false);
}

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: [URGENT] WTF Sprite being destroyed when visible?
« Reply #1 on: May 22, 2013, 11:08:38 pm »
It gets destroyed, as in the gameobject itself gets destroyed?

Edit:
Only way to figure this out is to debug it.
Attach a breakpoint to tk2dSprite.OnDestroy
Try to reproduce the bug, wait for breakpoint to hit. Work out why it hit.

p.s. there is nothing in the 2D Toolkit source that actually destroys a gameobject that is used at runtime.
« Last Edit: May 22, 2013, 11:13:09 pm by unikronsoftware »

CoderBear

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: [URGENT] WTF Sprite being destroyed when visible?
« Reply #2 on: May 29, 2013, 01:41:49 am »
yes the gameobject itself is destroyed.  I found out that if the spawner is disabled. then the the sprite appears and stays on screen until it is deactivated (setActive(false)).

Though that still doesn't explain why it has just now started when it had no issues previously.  Nor why this is the only tk2d sprite to have this issue.