Add and remove highlight w/interaction

is there a best practice for adding and removing a highlight with an interaction?


within my “draw loop”/“request animation frame”/“update” whatever, I have this code:

if (guardianOne.flashing == true && POV == false) {;
  hl.addMesh(guardianOne, BABYLON.Color3.Green());
} else {
  redSphere.wander({ weight: 10 }).seek(greenTarget);

for some reason, even though the console log shows me the highlight layer object, I can’t add the guardian on the next line. I get this error:

VM89:1284 TypeError: Cannot read property ‘add’ of undefined
at t.addMesh (babylon.js:16)
at (index):3299
at t._renderFrame (babylon.js:16)
at t._renderLoop (babylon.js:16)
at Object.renderFunction [as callback] (babylon.js:16)
at XRSession$1..onDeviceFrame (:1281:42)

How can it be undefined when I literally just console logged it the line before?

Could you also try to add
and see what is there :slight_smile:

when I console log the guardian I see it. :slight_smile:

I think I fixed this, I was referring to the guardian class, not the body mesh in the class, so it should be “guardianOne.body” dumb mistake

1 Like