Synchronize visibility of GUI controls linked with mesh

In my use case i have a dynamic scene composed by dozens of meshes arranged in a hieracy.

Attached to some of them there is a TextBlock (using linkWithMesh like described here Babylon.js docs)

The issue is that when the mesh with an attached label is disabled, the corresponding label remains visible.

I’m able to manage this using the onEnabledStateChangedObservable

But this doesn’t work if some of the ancestors of the mesh is disabled

Look at this minimal repro:

IMHO the design of onEnabledStateChangedObservable is flawed because it does not reflect the “real” EnabledState. In contrast the funcion isEnabled by default does it!!!

This may be fixed with a minimal change i’m proposing here WIP: feat(core): add onEnabledStateChangedObservableEx on Node by beppemarazzi · Pull Request #18722 · BabylonJS/Babylon.js · GitHub

cc @amoebachant

Hi @beppemarazzi - thanks for reporting this and for getting a head start on the fix!

I agree that it’s confusing that onEnabledStateChangedObservable doesn’t notify when the effective enabled state changes - it only notifies when the local enabled state changes. I took a look at your PR and agree that adding a second observable makes sense, but I’d prefer if it were lazy loaded. Take a look at my draft PR here: Add onEffectiveEnabledStateChangedObservable to node class by AmoebaChant · Pull Request #18726 · BabylonJS/Babylon.js · GitHub and let me know what you think.

Thanks again!

Thank you @amoebachant !!!

It definitely solves the issue!!!

Here the repro playground with your fix:

Thanks again!!!

You’re welcome, thanks for confirming it fixes it!