menu_bookDocumentation
Scene.Push(), BatchGroup(), FindInPhysics, and FindAllWithTag — Scene Context Management
Scene.Push() and Scene.BatchGroup(): Scene Context Management
Scene.Push()
Scene.Push() makes a scene the active scene for the duration of a scope. This is required when creating GameObjects or components outside of the normal game loop.CSHARP
var myScene = new Scene();
using ( myScene.Push() )
{
// Game.ActiveScene == myScene here
var go = new GameObject( true, "MyObject" );
go.AddComponent<MyComponent>();
// go is created in myScene
}
// Game.ActiveScene restored to previous sceneScene.BatchGroup()
BatchGroup() defers all OnEnabled, OnDisabled, and other lifecycle callbacks until the scope ends. This ensures deterministic callback ordering when creating multiple objects at once.CSHARP
using ( Scene.BatchGroup() )
{
// Create many objects — callbacks are deferred
for ( int i = 0; i < 100; i++ )
{
var go = new GameObject( true );
go.AddComponent<MyComponent>();
}
// All OnAwake, OnEnabled etc. fire here in deterministic order
}Scene.CreateObject()
CSHARP
// Create a GameObject on a specific scene (doesn't require it to be active)
var go = myScene.CreateObject( enabled: true );Scene.FindAllWithTag / FindAllWithTags
CSHARP
// Find all GameObjects with a tag
var players = Scene.FindAllWithTag( "player" );
// Find all GameObjects with all tags
var activeEnemies = Scene.FindAllWithTags( new[] { "enemy", "active" } );Scene.FindInPhysics
CSHARP
// Find GameObjects overlapping a sphere
var nearby = Scene.FindInPhysics( new Sphere( position, radius ) );
// Find GameObjects overlapping a box
var inBox = Scene.FindInPhysics( new BBox( mins, maxs ) );
// Find GameObjects in a frustum
var inFrustum = Scene.FindInPhysics( frustum );
Was this helpful?