[SOLVED] Script running in changing scenes

I have a tutorial scene whereby the player is asked to click on specific buttons to know the controls, this scene ends by redirecting to the main game scene, however after it redirects the script in the tutorial screen keeps running in the next screen and surely getting errors.
Can you help how can I stop this script?

Usually disabling or removing the entity that has this script attached to it, it will make the script stop executing.

This entity is the player, how can I disable it? As the player should be in the next scene for the game?

Then disable the script instance attached to the player. If the script is named … myScript:

playerEntity.script.myScript.enabled = false;

Hey Leonidas,
Thanks for the advice however it’s not working in throws this error:
Cannot read property ‘firstPersonMovement’ of undefined
also I tried another scripts but still no luck.

please advice and offcourse we can add you to the project for you to better understand the problem.

Is the UI using the PlayCanvas elements or HTML DOM objects? What errors were you getting in the first post? Feel free to share the project URL here too.

Just added you to the project, the tutorial scene is named Tutorial going to the main scene where the game is

It’s a pretty large project to debug and the Start scene crashes on startup. I’m afraid I don’t have time to dig into it.

From a glance, the tutorial is done in HTML which means that the DOMs are outside the PlayCanvas app. You need to manage those DOMs to be removed when the scene changes.

Any event listeners (such as mouse input) need to unsubscribed when the script/entity is destroyed (eg this.app.mouse.off("mousemove", this._onMouseMove, this);

That should hopefully solve most of your errors.

2 Likes

Solved Thank you

1 Like