Hiding Blender's Empty and children (isEnabled problem)

Hello,

I’m importing a very simple glb when one sphere is the child of an empty.
Hierarchy

In the great Scene Explorer, I noticed that when I select the empty (C1), I can turn isEnabled false to make it disappear (including its child).

I searched found this example for hiding/showing action:
https://www.babylonjs-playground.com/#8V8L47#2

I replicated lines [66;68] and it works for the spheres but not for the empty… or maybe the empty disappears but not its child.

scene.meshes[0].setEnabled(false) // works only for meshes

So, I know it is possible (I did it in the Scene Explorer) but I am currently not been able to do it.

Any idea?

well can you repro in the PG? it should work

https://playground.babylonjs.com/#H6AIXF#2
– see comments —

I get “root” when using scene.meshes[0].name but I get “CubeA” and “CubeB” when doing scene.meshes[1 or 2].name. Looks like “root” and other meshes are on the same level… weird.

However, scene.meshes[0].setEnabled(false) hides everything.

For now, the only way I access C1 (the empty parent of CubeB (subdivided Blue Cube)) and hide it is by doing this: scene.meshes[0]._children[0].setEnabled(false) I was told that I shouldn’t use private variables (_children) but I can’t find an alternative.

Any ideas?

why not relying on scene.getTransformNodeById in this case, it will actually ensure you will have the correct one ?

Thank you! It works!

There’s still something strange (or that I don’t understand) in the scene hierarchy but using getTransformNodeByID solves it.

Hello!

I updated your playground to use Seb’s solution so that future people can see what it looks like. Thanks for helping to contribute to Babylon documentation!

https://playground.babylonjs.com/#H6AIXF#3

3 Likes

Thank you. I made a little change to make use of the variable you declared (nameOfTransformNode).

https://playground.babylonjs.com/#H6AIXF#4

2 Likes

Great catch! Sorry for missing that.