[3.3.1] Component.onDestroy() is not called when a node is deleted in the editor

Hi devteam,

I found onDestroy() is not called for a component when its node is deleted in the editor.

Here is simplest component to reproduce:

import { _decorator, Component } from 'cc';
const { ccclass, executeInEditMode } = _decorator;

@ccclass('NewComponent')
@executeInEditMode
export class NewComponent extends Component {
    onLoad() {
        console.error('onLoad()');
    }

    onEnable() {
        console.error('onEnable()');
    }

    onDisable() {
        console.error('onDisable()');
    }

    onDestroy() {
        console.error('onDestroy()');
    }
}

You can add this component to the empty node in the editor and delete the node afterward. The output in the console will be:
image

So, there is no onDestroy() called.

But it is called when you delete component itself from the node.

I can ask engineering once they return from holiday.

:kissing_heart: Thank you for your feedback, this is a known issue for us and we are scheduling time to fix it.

The reason onDestroy is not invoke in the editor is because our undo system will need the object to restore its states. Once destroyed, the object is unusable, it’s quite hard to address currently. Will this actually cause any issue in your project ?

Hi there :slight_smile:
Is there any news concerning this issue ?
I’m working on a tool where the node deletion must be catched in editor mode to update some component. I have a workaround in mind but it will complicate the code drastically.
Do you plan to fix this in the 3.7 version to come ?

Thanks in advance :slight_smile: