Scene - KurbanismailovZaur/Extensions GitHub Wiki

On this page you can familiarize yourself with extension methods for the Scene type.

FindObjectOfType

Searches for an object with the specified component in the scene.

var renderer = go.scene.FindObjectOfType<SkinnedMeshRenderer>();

FindObjectsOfType

Searches for all objects with the specified component in the scene.

var renderer = go.scene.FindObjectOfType<SkinnedMeshRenderer>();

ObjectsCount

Returns the total number of objects in the scene.

print(gameObject.scene.ObjectsCount());

SceneReference

You can reference a scene directly from any script field. To do this, declare a field of type SceneReference. In your code, use the Path member to get the scene path, or simply specify a scene object to use an implicit cast from SceneReference to string.

//Declare a field in any script.
public SceneReference_scene;

198889672-f7d76d01-96c2-43de-bde2-c010b07d6170

To load a scene, make sure it is added to Build Scenes, and then use this code:

// Load the scene.
SceneManager.LoadScene(_scene);