Persistent node

Hello!

I want to make the object persistent. But I also need the object to be in different scenes.
How can you check whether an object exists? If exists, then destroy the current instance.

I’m using Cocos Creator version 3.8.1.

https://docs.cocos.com/creator/manual/en/scripting/scene-managing.html

I meant that I needed a design similar to the one in Unity

void Awake() {
if (instance != null) {
Destroy(this.gameObject);
return;
} else {
instance = this;
}
DontDestroyOnLoad(this.gameObject);
}

    this.node.removeFromParent();
    director.addPersistRootNode(this.node);

If you want to destroy the node if it already exists just do it the same way you would in C# with Unity (like in your snippet). Static members are supported by Typescript, onLoad is the Cocos equivalent of Awake, so it’s all transferable.

This does not work.