Get Button from GUI

Hi there,

This maybe a really dumb question to ask, but I have created some buttons with BABYLON.GUI, e.g.:

const button = Button.CreateSimpleButton(name, label);

Now I would like to get this button again from the scene by name, how could I achieve this?

I looked up all scene methods but couldn’t find any thing like scene.getGUIControlByName.

Thanks for the answer in advance!

Best,
Chen

Welcome aboard!

You can use getChildByName if you are using containers (StackPanel for eg). However, it will only look for direct children of the container. getDescendantsToRef will let you query for children by taking into account all the descendants.

I think the easiest way is simply to store somewhere (in a map, for eg) your “pointers” to be able to access them later on.

1 Like

Hi Evgeni,

Thanks a lot for the very prompt answer. Yes I’ve stored them in a custom map as a workaround. getChildByName doesn’t really help as if I can get the parent, I can as well get the child :slight_smile:

Looks like custom map is the way to go then.