[SOLVED] Bug about entity-finding

Suddenly I have to re-define a model like this:

(at intialize)

var entityCG3000 = new pc.Entity();
this.entityCG3000 = this.app.root.findByName('Cg3000_01');
this.entityCG3000.enabled = false;

(at function later)

setInterval(function() {
    this.entityCG3000 = this.app.root.findByName('Cg3000_01');
  • which wasn’t nessesary earlier (looks like a bug :-/ )

I’m really not sure what you’re trying to achieve with that code. In the first block, you are create a new pc.Entity and assigning it to a local variable called entityCG3000. Then, you’re assigning the result of a call to findByName to a member variable with the same name. And then you’re disable that entity.

Then, you have a block that calls setInterval. The function fires an event called startLigthUp3 (note that you spelled ‘light’ wrong in the variable name but as long as you’re consistent, it’s not a huge problem). Then you’re setting this.entityCG3000 to the result of another call to findByName. Unless you appended .bind(this) to the function passed to setInterval, the value of this will not be the same as it is outside the scope of that function’s body.

Ultimately, the moral of the story here is that, if you want people to help you solve problems here, it definitely makes sense to post the link to a small reproducible scene that illustrates the full context.

Came to a parallel conclusion, as my other pc did not fail this issue :-/ … you can deactivate this topic (if needed)

1 Like