public static SceneBase GetParentScenes(SceneBase scene, List <TransitionInfo> toRootScenes) { if (scene.transform.parent == null) { Debug.Log("root: " + scene.gameObject.name); return(scene); } SceneController sceneController = scene.GetSceneController(); if (sceneController == null) { Debug.Log("null parentSceneController"); return(scene); } if (sceneController != null) { int id = sceneController.GetSceneIdByScene(scene); if (id > -1) { TransitionInfo sceneAndId = new TransitionInfo(sceneController, id); toRootScenes.Add(sceneAndId); SceneBase parentSceneBase = sceneController.gameObject.GetComponentInParent <SceneBase>(); if (parentSceneBase != null) { return(GetParentScenes(parentSceneBase, toRootScenes)); } else { SceneBase mySceneBase = sceneController.gameObject.GetComponent <SceneBase>(); return(mySceneBase); } } else { Debug.LogWarning("Error SceneId: " + scene); return(scene); } } return(scene); }