I have a scene with a camera I’m carrying over from one scene to the next. The problem is that if I return to the first scene, I get an error because there’s two cameras. Since the first camera isn’t being instantiated, I need a way to make it behave as a singleton. Everything I can find on Singletons in Unity involves instantiated objects, not objects that are in the scene to begin with.
Solved it myself ![]()
private static int mainCamera = 0;
...
if(mainCamera == 0)
{
mainCamera = this.GetInstanceID();
}
else if(mainCamera != this.GetInstanceID())
{
Destroy(gameobject);
}
Congo rats on finding the solution. And thank you for sharing the solution so that others may find it and benefit rather than just posting “NVM, fixed it myself.” ![]()