SceneRef

A class to help with referencing between scripts.

Scarlet.Runtime

Scarlet.General

Usage

The class is static so all you need to do is to use the classes method GetComponentFromScene() or GetComponentsFromScene(). Note this just gets from the active scene. If using a multi-scene setup then its recommended you get MultiSceneRef from Multiscene. The script works by getting all root objects in the scene and checking their children for the script in question instead of going through each object individually.

For a single reference of just 1 object/script use the following. This uses the multiple get method but returns the first found.

private TestScript testScript;

private void SomeMethod()
{
    testScript = SceneRef.GetComponentFromScene<TestScript>();
}

For multiple, you can get a list of all found using the following.

private TestScript testScript;

private void SomeMethod()
{
    testScript = SceneRef.GetComponentsFromScene<TestScript>()[0];
}