Hello Guest

Author Topic: Is it not definite when some internal functions are called?  (Read 2075 times)

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Is it not definite when some internal functions are called?
« on: February 26, 2014, 03:58:26 pm »
Hi,

I'm making some UI with tk2d and used some Checkbox prefab from tk2d to do so. What I do is I check if the Checkbox's GetComponent<tk2dUIToggleControl> ().IsOn is true, I do something then toggle it and by default when the game starts, all the buttons are ON.

Problem is, when I click on these check boxes that are duplicates of each other, in OnClick event, 2 of them report IsOn as False and 3 of them report it as True.

What I assume is that somewhere in tk2d, they are first toggled off and then my OnClick event handler runs but for 3 of them, I first get the Onclick event handler then tk2d (or Unity) takes control and sets it off.

Check thise scene: https://www.dropbox.com/s/n4s2mifi0os7507/shop.unitypackage
(It doesn't have your package)

And check the OnClick event for first button and 2nd button from the left for example. In ShopController.cs file, in Toggle_Equip_Of_PowerUp_1_Click if you put a debug.log you can see that it returns True for IsOn and it's good and what I expect it because in the scene it's toggled true for Is On but the second button from the left's Toggle_Equip_Of_PowerUp_2_Click returns false for IsOn check.

Hope it shows the same behavior on your system as well.

Let me know if you have problem reproducing it.

Best.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Is it not definite when some internal functions are called?
« Reply #1 on: February 27, 2014, 01:42:52 pm »
Do you have nested prefabs here? There is a really really nasty bug in Unity that as far as I know is still not fixed where you have nested prefabs, and Awake / Start is called in a backward way before the object is deserialised.

So what happens is the object is created, then your awake gets called and sets something, then something else in Unity sets all the default values based on the prefab, and THEN calls Awake / Start on the object. I've sent unity a repro case for this but as usual not heard anything back beyond "we could reproduce it and have sent it to the developers".

If that is the case, try disconnecting the prefab (the root prefab especially) to see if it helps.

test84

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Re: Is it not definite when some internal functions are called?
« Reply #2 on: March 02, 2014, 08:25:15 pm »
Thanks,

I was using OnClick but apprently Toggle event was meant to be used for those toggle controls. Only if tk2d had better documentation ...