Description
The Scene
property of a Component
provides a reference to the Scene
that the component's GameObject
is part of. This property acts as a convenient shortcut to access the scene directly from the component, without needing to go through the GameObject
.
Usage
Use the Scene
property when you need to access or manipulate the scene that a component is part of. This can be useful for operations that involve scene management, such as loading or unloading scenes, or when you need to query scene-specific data.
Example
// Example of accessing the Scene property from a Component
public class MyComponent : Component
{
public void PrintSceneName()
{
// Access the Scene property
Scene currentScene = this.Scene;
// Print the name of the scene
Log.Info($"The component is in the scene: {currentScene.Name}");
}
}