[SOLVED] Bug in entity.fire and entity.on?

A small error is happening to me that I think is a bug, I will explain what happens to me.
In the create character scene, you just select a Trainer, Adan or Eva.


That calls this function to create the Trainer entity
image
The GameCreate_CreateTemplate function is this:
image
that function stores the Trainer entity here:
pc.app.root.findByName(“Root”).findByName(“CrearScene”).playerSelected

Here comes my problem, this entity has an active script called pGlobal.js

and that script is active in the game when you create it

within that script I have created an on method to receive a call “test” that will execute a console.log to verify that it receives the call
image
when executing that call in the console, the script inside the entity does not receive it

And when I run it directly from the script it works

could you help me with that please? I spent hours thinking and I can’t think what could have happened.
This is my scene in case you want to take a look:
https://playcanvas.com/editor/scene/1389734

Hi @ignacio_padilla,

I think your pGlobal.js script never reaches line 22 to actually add the event handlers. Stepping through with the debugger I can see that this line, line 7, is false and exits the method:

image

That’s why your event handlers fails silently.

2 Likes

I forgot about that line, I didn’t even see it, Thanks so much Leonidas you save me!

1 Like