I have a simple SpherePanel GUI object and I want to toggle it’s visibility on and off. I gave the panel a name and thought that I could use that name to query the panel in the scene later on. I can’t seem to find the panel when I look for it
let name = "panelName";
let findPanel = scene.getNodeByName(name);
console.log("panel: ", findPanel); // showing as null
//findPanel.isVisable = !panel.isVisable; // undefined because I can't find the panel by name
Is there a better way to find this panel?
Here is a basic playground with the named panel.
The 3D GUI elements are created in a utility layer scene, so you won’t find them in the regular scene.
This utility scene can be found on GUI3DManager.utilityLayer.utilityLayerScene
.
Also, the panel is created with the default name ContainerNode
. If you want to change this name, you need to override the _createNode
function:
_createNode(scene) {
return new TransformNode("ContainerNode", scene);
}
Lastly, you need to use the setEnabled
method of the node class to show/hide the panel.
Here’s a PG with those changes:
https://www.babylonjs-playground.com/#HB4C01#381
1 Like
Wow I guess I was way off track. I assumed that naming the panel using its name property would be the direction to go. It seems that property is of no use here. I removed the calls to panel.name
and used the method you described to rename the panel. Updated playground
Somehow I missed the line in the documentation about the utility scene. I had no idea a scene could have other scenes inside it. Weird, but kind of awesome.
Thanks for your help 