[SOLVED] Question about scene and script destroying

Hi guys,
I ve some problems about scene destroying and script destroying,Probably simple things but i cant figured it out.

I have 4 scene and changing between scenes thats ok.But when i change a scene , previous scene’s scripts dont stop and running.I destroy the old Hierarchy.But still running previous scene’s scripts.

The code that i’ve used is this

SceneManager.prototype.changeScenes = function(sceneName) {

    const allScenes = pc.app.scenes.list(),   
          targetSceneData = allScenes.find(e=>e.name === sceneName);

    if(!targetSceneData)throw new Error('Wrong Scene'); // Checking...
    const sceneId = targetSceneData.url, oldHierarchy = this.app.root.findByName ('Root');   
 
               oldHierarchy.destroy();
               this.loadScene (sceneId, (function (par) {
                console.log(`${sceneName} Loaded successfully`);
                currentScene = sceneName;

                pc.app.lightmapper.bake();
            }).bind(this));
};

SceneManager.prototype.loadScene = function (id, callback) {

    pc.app.scenes.loadSceneHierarchy(id, function(err, parent){ 
        if(!err){
            callback(parent);
        } else {
            console.error (err);
        }
    });

};

This is not working for me.
And so i wanted to create a workaround for this.And i disable or destroy the entity which has scripts like this.

  this.manager.script.destroy('sc');
        this.entity.script.destroy('sc');
          pc.app.root.findByName('manager').removeComponent('script')

But scripts never stops.Do you know something about this issue?

What do you mean by ‘keeps running?’ Can you share the project please?

Do you have events that have been registered by scripts and haven’t been unregistered when destroyed?

i think i kind of figured it out now ehwn you say events.When you destroy a scene or an entity that have some scripts , i thought all events registered to that entity or app is destroyed by engine.But that s not true.Cause all events keeps running and i think i should set them off manually.Am i right?

Events attached to an entity or script instance will be automatically released when that entity is destroyed.

But for app events, yes, you will have to manually release them.

Ok thanks guys