Destroy object if one already exists upon load

so i have a simple gameobject that i want to DontDestroyOnLoad(gameObject); And check if upon loading a new scene if itself already exists and if so it will destroy itself. how could i go about doing this?

Good day @Yogurt_ .

I write you the logic, not the code:

Fisrt, you have to create a bool variable, called for example “TheGoodObject”, which must be activated in the correct object to preserve

And then, at the Start() or Awake() look for all GameObject like that (i recommend to create a tag, assign it, and use FindObjectsWithTag(“Tag”) to find them all.

The first time you do it, the array resulting of the search lenght is 1, means there is only one, so you must activate its bool variable.

All next times you make the search, will find your “goodObject” and otherone without the bool actiavted. This way, every time the Start() executes, will find the correctone and do nothing with it (preserve) and destroy the badones.

If helped, Accept the answer and close the Question!