1
NGUI 3 Support / UILabel.parent != UIlabel.transform.parent
« on: May 13, 2015, 08:13:47 AM »
This is a bit of a strange one, as I've managed to get away with a few of these (typos) in my code *until* I upgraded to version 3.8.2
I've got a reference to a UILabel representing a decimal value and that's parented to another UILabel which contains a string describing what the value means.
Sort of:
UILabel "Bonus Multiplier = "
>UILabel "100"
If the value itself is zero, I decide to SetActive(false) the parent so that both the value and the parent label containing the string description aren't displayed.
Anyway, I failed to dereference to 'UILabel.transform.parent.gameobject' for the SetActive(false), instead just using 'UILabel.parent.gameObject', but prior to my upgrade, this worked fine.
Indeed, this DOES continue to work fine on the first pass when the parent UILabel is deactivated ( and as a consequence the value label ) but on the second pass, instead of the *value* UILabel's parent reference being 'correct', it instead references UIRoot and any deactivation I apply to that results in, rather unsurprisingly, the whole UI disappearing.
The value UILabel is buried several deep in the hierarchy, well away from UIRoot, so I'm not sure how this leap is occurring.
I have of course now corrected this by explicitly using the 'correct' transform.parent method, but I'd be really interested to hear any theories as to why this new behaviour has decided to manifest just after an NGUI update and not before?
Many thanks.
I've got a reference to a UILabel representing a decimal value and that's parented to another UILabel which contains a string describing what the value means.
Sort of:
UILabel "Bonus Multiplier = "
>UILabel "100"
If the value itself is zero, I decide to SetActive(false) the parent so that both the value and the parent label containing the string description aren't displayed.
Anyway, I failed to dereference to 'UILabel.transform.parent.gameobject' for the SetActive(false), instead just using 'UILabel.parent.gameObject', but prior to my upgrade, this worked fine.
Indeed, this DOES continue to work fine on the first pass when the parent UILabel is deactivated ( and as a consequence the value label ) but on the second pass, instead of the *value* UILabel's parent reference being 'correct', it instead references UIRoot and any deactivation I apply to that results in, rather unsurprisingly, the whole UI disappearing.
The value UILabel is buried several deep in the hierarchy, well away from UIRoot, so I'm not sure how this leap is occurring.
I have of course now corrected this by explicitly using the 'correct' transform.parent method, but I'd be really interested to hear any theories as to why this new behaviour has decided to manifest just after an NGUI update and not before?
Many thanks.