[SOLVED] Entities not accessible in playcanvas-ar.js


#1

Hi all,

I am trying to access an entity in the PlayCanvas-ar,js script when the camera ‘sees’ the AR Hiro marker.
This is the code where I try to access the entity via this.app.root.findByName().

The code is just meant to alert the entity’s position like so -


alert(this.app.root.findByName('Box').getPosition);

However, I get an error saying that undefined is not an object, though “Box” is clearly part of my entity hierarchy -

07%20PM

Why can’t I access ‘Box’? Please help me out!


#2

You have lost the context of the function and did not call the method. Try changing the code like this: alert(self.app.root.findByName('Box').getPosition());


#3

Thanks a lot @MasalovAndreey!