Watermaterial scoping / code-structure issue (vr)

Hi,

I’m continuing to hack the babylon vr physics example, and continuing to work through what I imagine is the difference between “scene as promise” and “scene as scene object” (I have posted about this before).

You can see a demo here, the scene is getting pretty interesting: https://twitter.com/delta_ark/status/1336454691471835136

I was able to implement the water/object material in the “setup” function of my code, but when I implement the same code as a function that one of my agent calls, I get this error:

babylonjs.materials.min.js:16 Uncaught TypeError: Cannot read property 'clipPlane' of undefined
    at r._reflectionRTT.onBeforeRender [as callback] (babylonjs.materials.min.js:16)
    at e.notifyObservers (babylon.js:16)
    at t.renderToTarget (babylon.js:16)
    at t.render (babylon.js:16)
    at t._renderForCamera (babylon.js:16)
    at t._processSubCameras (babylon.js:16)
    at t.render (babylon.js:16)
    at (index):3323
    at t._renderFrame (babylon.js:16)
    at t._renderLoop (babylon.js:16)

index line 3323 is the following:
if (sceneToRender) {
3323 --> sceneToRender.render();
}

I have isolated the problem to one line of code (336, it’s inside one of my agent’s functions):

waterMesh.material = water;

When I console log waterMesh and water, they both show up; so, I’m not sure why I can’t set them to each other.

In the past, I have gotten my other agent function code to work by referring to the scene as createScene.scene. So, I’ll create a box and attach it to createScene.scene, and then everything works in the agent function.

Feel free to look at the code here: Glitch :・゚✧ . Again, I can’t put it in a playground bc the code is too large at this point; it’s a full VR game.

Help with getting this water material stuff to work would be really appreciated.

1 Like

OK, and just nailed it.

the scene must be “sceneToRender” inside of the encapsulated f(x)

1 Like