DoNotDestroyAccessor.cs

Back


Assembly: CarterGames.MultiScene.Runtime

Namespace: CarterGames.Experimental.MultiScene.DoNotDestroy


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


Root Objects


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();

Move Objects


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.


Moves the gameObjects entered into the do not destroy scene.


List<GameObject> objs;
DoNotDestroyAccessor.MoveObjectsToSceneInDoNotDestroy(objs);

Find Objects


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");

Get Components


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>();