[SOLVED] Event handling on persistent entity across scenes

Hi,

I was trying what event in playcanvas can do in many case, one of which is detailed in the scenario:

There’re 2 scenes called ‘Untitled’ and ‘Untitled1’, in the first scene there’s a entity called ‘persistent’ which is persistent

in scenes. I attached event with scene1.js(in Untitled) and scene2.js (in Untitled1) respectively onto entity persistent

which fires event in periods.

In scene Untitled it worked normally(it set a boolean variable to signal box scaling animation), but in second one it

didn’t. The event fired but handler was not triggered. And here’s the sample project I made for reference.

https://playcanvas.com/project/480108/overview/eventacrossscenes

Any suggestion? Thanks!

CL-Wu

Looking at the code, you have put the event handler on the persistent script rather than the entity in scene2.js

// initialize code called once per entity
Scene2.prototype.initialize = function() {
    this.camera1 = this.app.root.findByName ('Camera1');
    this.persistent = this.app.root.findByName ('Persistent').script.persistent;
    this.persistent.on('persistent:start', this.box1.script.animateScale.getStart, this.box1.script.animateScale);
};

What it should be is:

// initialize code called once per entity
Scene2.prototype.initialize = function() {
    this.camera1 = this.app.root.findByName ('Camera1');
    this.persistent = this.app.root.findByName ('Persistent');
    this.persistent.on('persistent:start', this.box1.script.animateScale.getStart, this.box1.script.animateScale);
};

Hi,

Thanks, You’re right! problems solved.(sorry for the late replay)

1 Like