[SOLVED] HighlightLayer + onNewMeshAddedObservable issue on babylonjs 4


found weird bug in babylonjs 4
here is playground


scene.onNewMeshAddedObservable.add(function (mesh) {
            if (mesh instanceof BABYLON.Mesh) {

is called before mesh gets props so it crashes with random errors,
usually with Cannot read property '_onBeforeBindObservable' of undefined,
because _internalMeshDataInfo is still undefined

I am doing something wrong ? :slight_smile:

Thank you

Ok looks like its expected as observable is triggered in AbstractMesh constructor so Mesh constructor is not finished at that point

this is correct. Best solution is to call your code inside setTimeout(func, 0)

Thank you @Deltakosh,
yes thats what I ended up

scene.onNewMeshAddedObservable.add(mesh => {
            if (mesh instanceof Mesh) {
                Tools.SetImmediate(() => {
1 Like