UI components slider scene change problem

Hello

I was doing some testing with this UI project https://playcanvas.com/project/644577/overview/uicomponents

For the slider when changing a scene the inside part of the slider still remains in the next scene like this.

Scene 1

Scene 2

My test project that demonstrates the above

Why does this still remain in the next scene? How can I unsubscribe it?

Thank you

Hi @nasjarta,

You should better ask the original author of the project about that, most likely somewhere there are event handlers that require additional clean up on scene change.

Here is the original thread:

2 Likes

Because it’s a HTML dom element that’s added to the page document, not a PlayCanvas entity that’s part of the scene.

On the destroy event of the script type for Slider.js, you have to remove the dom element from the page.

2 Likes

Hello, thanks the solution was simple. Just added the below to the initialize function.

this.on('destroy', function() {
    this.element.remove();
});

Also a noob question regarding best practice, when you use the destroy event does it clean up the events on scene change or do i need to use this.app.off somewhere too?

Thanks

1 Like

You always need to manage the event subscribers. If a script is listen to an event on the app object for example, it is also responsible for removing the subscriber when the script is destroyed.

See this ticket for more details API to make registering events in scriptType easier · Issue #4910 · playcanvas/engine · GitHub

1 Like