[SOLVED] [ENGINE ONLY] Start Stop script when changing a scene

Hello,

I am using changeScene() to change a scene, each scene has different scripts running on an entity.
I have the problem that the script continues running when the scene changes.
How can I avoid this so that the script will restart each time I change the scene?

Thanks!

It shouldn’t if the entity it is attached to is destroyed. Is it event driven and if so, are you removing the event listeners when it is destroyed?

Can you replicate the issue in an Editor project?

Honestly I am a bit lost here, issue coming from a tween.js script
image

Have to figure out…

Interesting is that its working when I use loadSceneHierarchy() instead of changeScene(), but I want changeScene() of course

If you can post the Editor project that showcases the issue, the community can help investigate

It works now so far. It was some issue with the entity. Only thing now is that I cannot fully destroy the tweens / tween js. The tweens are kinda going crazy when I change the scene and switch back. As mentioned in the headline of this thread, I am using Engine only (and Vue3).

I do something like this in my Script in the initialize function:

    for (i = 0; i < this.tweens.length; i++) {
      if (this.tweenInstances[i]) {
        this.tweenInstances[i].stop();
        this.tweenInstances[i] = undefined;
      }
 }

Yes, I asked if the issue could be replicated in the Editor as it makes it a lot easier for other people to help.

Right now, its incredibly difficult to help without a repro

Understandable… In the meantime I solved it by using TWEEN_JS.removeAll() bruteforce :slight_smile: