FindObjectsOfType(Transform) confusing me

Hey I have a scene that has one gameobject with a couple of children (global lights an the main camera) but everything else is generated via the function “BuildLevel()”,

I would like to be able to get back to the previous state before I called “BuildLevel()” so that if a user changes an option or a new game starts I don’t have to keep loading the same scene over and over again. I could just delete everything but the main controller and call “BuildLevel()” again.

I attempted using “FindObjectsByType(Transform)” and filtering the results but it did not remove anything from the level. It is extremely possible that I just dont understand the data returned by “FindObjectsOfType()” or that I just don’t understand Transforms very well (I tried “FindObjectsOfType(GameObject)” first)

here is what I have that doesn’t work

var old = FindObjectsOfType(Transform);
for (var object : Transform in Old) {
  if (object.name != "Level"  object.name != "MainCamera"  object.name != "Sunlight") {
    Destroy(object);
  }
}

any suggestions?

try Destroy(object.gameObject) since the local variable is a transform.