2D Toolkit Forum

2D Toolkit => Support => Topic started by: gerlonx on March 10, 2012, 01:05:45 pm

Title: gameObject.SetActiveRecursively() will fail tk2dButton
Post by: gerlonx 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?
Title: Re: gameObject.SetActiveRecursively() will fail tk2dButton
Post by: KyleStaves 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).
Title: Re: gameObject.SetActiveRecursively() will fail tk2dButton
Post by: gerlonx 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.  ;)
Title: Re: gameObject.SetActiveRecursively() will fail tk2dButton
Post by: unikronsoftware 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.