• Hi Guest!

    We are extremely excited to announce the release of our first Beta1.1 and the first release of our Public AddonKit!
    To participate in the Beta, a subscription to the Entertainer or Creator Tier is required. For access to the Public AddonKit you must be a Creator tier member. Once subscribed, download instructions can be found here.

    Click here for information and guides regarding the VaM2 beta. Join our Discord server for more announcements and community discussion about VaM2.
  • Hi Guest!

    VaM2 Resource Categories have now been added to the Hub! For information on posting VaM2 resources and details about VaM2 related changes to our Community Forums, please see our official announcement here.

Coding question: pressing UI button, connected to a Parent atom, from code

bot1789

Member
Joined
May 1, 2023
Messages
68
Reactions
93
Hello everyone!
I want to add a On click-Listener to an UIbutton from my script using the following code:

C#:
Atom uiButtonAtom = SuperController.singleton.GetAtomByUid(uiButtonName);
Transform buttonTransform = uiButtonAtom.transform.Find("reParentObject/object/rescaleObject/Canvas/Button");
UnityEngine.UI.Button myButton_1 = buttonTransform.GetComponent<UnityEngine.UI.Button>();
myButton_1.onClick.AddListener(ClickUIButton);

This works fine if the UI button atom has no parent, but fails if another atom is declared as its parent.
I would like to ask if there is a way to do the same if the UI button has a parent atom?
 
A bit late, but instead of uiButtonAtom.transform.Find("reParentObject/... use uiButtonAtom.reParentObject.Find("...
 
A bit late, but instead of uiButtonAtom.transform.Find("reParentObject/... use uiButtonAtom.reParentObject.Find("...
It's not too late! Thank you for the tip!
It really works if I do like this:
C#:
Transform buttonTransform = uiButtonAtom.reParentObject.Find("object/rescaleObject/Canvas/Button");
 
Yeah. Parenting an atom changes the "reParentObject" transform's location in the scene hierarchy, but that doesn't matter when you use the direct reference to that transform :)
 
Back
Top Bottom