The solution only works if you don't rely on transform.root anywhere in your game. It also doesn't work if you need to find objects that are children of objects that don't get destroyed on load.
Add a GameObject that is the root of all GameObjects in your scene. Then instead of
FindObjectsOfType()
use
GetComponentsInChildren( typeof(Transform), true );
That should return all transforms of all GameObjects in the scene as they are all a child of the scene root, active or not.
If you can't or don't want to create a scene root object then you'll need to make an array of all the root objects in your scene and all GetCompoenentsInChildren() on all of them separately.
↧