I am having trouble accessing a object in my scene. I've figured out the reason I wasn't able to access it was because the Raytracer was loading before the world had finished loading. It works fine for objects added by code, but it doesn't work when looking for objects imported by GLTFLoader.
I have set up something to trigger an event when all the objects have been loaded. But I am unable to access the variable inside of the check in my update function.
setRayCaster()
{
this.rayCaster = new THREE.Raycaster()
this.foundButton = this.main.scene.children.find(child => child.name === 'Test')
this.objectsToTest = [this.main.scene.children.find(child => child.name === 'Test')]
this.resources.on('ready', () =>
{
this.UNABLETOACCESSTHIS = this.scene.getObjectByName('Trackpad')
})
}
update()
{
this.rayCaster.setFromCamera(this.cursor, this.camera.view)
this.intersects = this.rayCaster.intersectObject(this.foundButton)
UNABLETOACCESSTHIS.here
for(const object of this.objectsToTest)
{
object.material.color.set('#ff0000')
}
for(const intersect of this.intersects)
{
intersect.object.material.color.set('#0000ff')
}
// console.log(this.intersects)
}
}