Hi. I am trying a 2D plane disappear after 1 second. However, when I try to do this, I get this error: Uncaught TypeError: Cannot read property 'root' of undefined.
Here is my code:
var app = this.app;
var screen4 = app.root.findByName('Frame').findByName('Screen4');
screen4.enabled = true;
setTimeout(function () {
screen4.enabled = false;
}, 1);
this.app to access the application instance is available in pc.script functions. It looks like you are trying to access it in the global where this.app is undefined.
The issue is less about the code and the syntax and more on the understanding of context, scope and where you have access to certain objects. this.app is available within the scope of a pc.script function and I’m guess you are trying to use it in global scope where it would be undefined.
How much do you know about local, function and global scope along with what the this keyword means?
Oh I am very dumb.
I tried using findByName without putting it in script.prototype.initialize(). I am getting started with playcanvas, so I’m learning.
Anyway thanks for the help, this community is very helpful