Game Object adds itself back after scene reload?
Here is the base Code. Literally as simple as it gets.
namespace CompanyName
{
namespace Spawning
{
public class Spawner
{
public SpawnCluster [] cluster;
void OnEnable()
{
Debug.Log(cluster.Length);
}
}
}
}
[System.Serializable]
public class SpawnCluster
{
public string name;
public int count;
public int max;
public Vector3 bounds;
public Vector3 center;
}
This is part of a massive spawner, but ended up stripping EVERYTHING out of it until this was the only code left, that still allowed the issue to be reproducible.
Important Notes
The spawner is never modified or referenced externally.
I have no custom editors of any type in this game.
The spawner is in a custom name space, as i have another identically named spawner in a different namespace. However, I removed it from the namespace and the problem persists.
I have also tried remove the parent gameObject, closing unity and restarting and running the game again. It adds itself back after the scene reloads.
if I removing the game object and run the game, the object adds itself back (LIKE WTF?)
The Array has content when i first start
The array loses its content when the scene is reloaded.
a new script with the exact same content but a different name does not have the same issue.
I have tried the usual suspects... reloading and rebooting.
It is like there is a snapshot of my scene somewhere and its locked.
Answer by triangle4studios · Jul 23, 2021 at 04:34 AM
Somehow, unity created a copy of my Scenes folder inside a random folder. Perhaps I did it accidentally when dragging lag occurred which unity is notorious for. Regardless, what ended up happening, is the scene created a new copy of itself, when it was missing and so I was not aware this happened.
Simply removing the duplicate scene solved the issue. Most absurd debugging issue I have ever had. But very very happy it has been resolved.
nice, i guess this can be a potentially annoying issue to debug. Not sure if i could have done anything if i was in your place.