A class to allow access to the objects in the do not destroy scene when your game is in play-mode/build. This class just has methods similar to the Multi Scene Ref class, but all of them are solely focused on the do not destroy scene. In earlier versions of this asset this was an extensions to the core library. It has been added as a built-in feature from 0.2.0
as it has a lot of use-cases and no dependencies.
Methods
GetRootGameObjectsInDoNotDestroy
Method
Returns
List<GameObject>
โ The root objects of the do not destroy scene.
Gets all the root gameObjects in the do not destroy scene and returns what it finds.
var objs = DoNotDestroyAccessor.GetRootGameObjectsInDoNotDestroy();
MoveObjectToSceneInDoNotDestroy
Method
GameObject
โ The object to move.
Move the gameObject entered into the do not destroy scene.
GameObject obj;
DoNotDestroyAccessor.MoveObjectToSceneInDoNotDestroy(obj);
MoveObjectsToSceneInDoNotDestroy
Method
List<GameObject>
โ The objects to move.
Move the gameObjects entered into the do not destroy scene.
List<GameObject> objs;
DoNotDestroyAccessor.MoveObjectsToSceneInDoNotDestroy(objs);
FindObjectInDoNotDestroy
Method
string
โ The name of the object to find.
Returns
GameObject
โ The gameObject found.
Tries to find an object of the requested name. If it fails itโll return null.
var obj = DoNotDestroyAccessor.FindObjectInDoNotDestroy("MyObject");
FindObjectsInDoNotDestroy
Method
string
โ The name of the object to find.
Returns
List<GameObject>
โ The gameObjects found.
Tries to find all objects of the requested name. If it fails itโll return null.
var objs = DoNotDestroyAccessor.FindObjectsInDoNotDestroy("MyObject");
GetComponentInDoNotDestroy
Method
Returns
T
โ The type requested.
Gets the first component of the requested type from the do not destroy scene, if it fails to find anything itโll return the default for the type requested.
var component = DoNotDestroyAccessor.GetComponentInDoNotDestroy<MyComponent>();
GetComponentsInDoNotDestroy
Method
Returns
List<T>
โ A list of the type requested.
Gets all components of the requested type from the do not destroy scene, if it fails to find anything itโll return the default for the type requested.
var components = DoNotDestroyAccessor.GetComponentsInDoNotDestroy<MyComponent>();