Hello Guest

Author Topic: gameObject.SetActiveRecursively() will fail tk2dButton  (Read 7025 times)

gerlonx

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
gameObject.SetActiveRecursively() will fail tk2dButton
« on: March 10, 2012, 01:05:45 pm »
I had parenting some buttons in another gameobject, I tried to SetActiveRecursively(false) the parent and back to (true), and all buttons could not work. Is there another solution to make active/inactive all at once effectively?

KyleStaves

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: gameObject.SetActiveRecursively() will fail tk2dButton
« Reply #1 on: March 10, 2012, 07:02:58 pm »
If the button is currently animating when it gets disabled it breaks. Adding this fixed it for me:

Code: [Select]
void OnEnable(){
buttonDown = false;
}

You probably want to run some cleanup too, to ensure your buttons appear correctly after the disabling if you do any sort of scaling. I ended up just writing my own button script (I'll share it eventually, not in a great state atm though - and it depends on the "FingerGestures" plugin anyway).

gerlonx

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: gameObject.SetActiveRecursively() will fail tk2dButton
« Reply #2 on: March 10, 2012, 09:49:43 pm »
If the button is currently animating when it gets disabled it breaks. Adding this fixed it for me:

Code: [Select]
void OnEnable(){
buttonDown = false;
}

You probably want to run some cleanup too, to ensure your buttons appear correctly after the disabling if you do any sort of scaling. I ended up just writing my own button script (I'll share it eventually, not in a great state atm though - and it depends on the "FingerGestures" plugin anyway).

Hey it works, thanks.
Well it seems I was too lazy to check the source code  :P

While I was waiting for this answer, I was in the middle of finding another solution with moving its parent position, but that was double-work for me.

Oh, and I'm still curios about your script.  ;)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: gameObject.SetActiveRecursively() will fail tk2dButton
« Reply #3 on: March 10, 2012, 10:07:40 pm »
Hi KyleStaves, thanks for posting your fix. I will integrate that and merge in the multitouch version as soon as I can. Never really noticed this issue, thanks for bringing it up.