menu_bookDocumentation

ISceneCollisionEvents, IScenePhysicsEvents, ISceneLoadingEvents — Physics and Loading Callbacks

calendar_today May 4, 2026 schedule ~1 min read person patrickjr verified 50

ISceneCollisionEvents and IScenePhysicsEvents: Physics Callbacks

ISceneCollisionEvents

Implement this interface on a component to receive collision callbacks. Unlike ISceneEvent, this is not posted via Scene.RunEvent — it is called directly by the physics system on the component.

CSHARP
public class MyComponent : Component, ISceneCollisionEvents
{
    public void OnCollisionStart( Collision collision )
    {
        // Called when this collider first touches another
        Log.Info( $"Started touching {collision.Other.GameObject?.Name}" );
        Log.Info( $"Contact point: {collision.Contact.Point}" );
        Log.Info( $"Impact speed: {collision.Contact.Speed}" );
    }

    public void OnCollisionUpdate( Collision collision )
    {
        // Called once per physics step while touching
    }

    public void OnCollisionStop( CollisionStop collision )
    {
        // Called when contact ends
        Log.Info( $"Stopped touching {collision.Other.GameObject?.Name}" );
    }

    public void OnCollisionHit( Collision collision )
    {
        // Called on every hit, including repeated hits on the same shape
        // while already touching. Use this for impact sounds/effects.
    }
}

IScenePhysicsEvents

Implement this interface (on a component or GameObjectSystem) to hook into the physics step:

CSHARP
public class MySystem : GameObjectSystem<MySystem>, IScenePhysicsEvents
{
    public MySystem( Scene scene ) : base( scene ) { }

    public void PrePhysicsStep()
    {
        // Called right after FixedUpdate, before physics simulation
    }

    public void PostPhysicsStep()
    {
        // Called after physics simulation completes
    }

    public void OnOutOfBounds( Rigidbody body )
    {
        // Called when a rigidbody leaves the physics world bounds
        body.GameObject.Destroy();
    }

    public void OnFellAsleep( Rigidbody body )
    {
        // Called when a rigidbody goes to sleep (becomes inactive)
    }
}

ISceneLoadingEvents

Hook into scene loading at various stages:

CSHARP
public class MySystem : GameObjectSystem<MySystem>, ISceneLoadingEvents
{
    public MySystem( Scene scene ) : base( scene ) { }

    public void BeforeLoad( Scene scene, SceneLoadOptions options ) { }

    public async Task OnLoad( Scene scene, SceneLoadOptions options, LoadingContext context )
    {
        context.Title = "Loading My Data...";
        await LoadMyData();
    }

    public void AfterLoad( Scene scene )
    {
        // Scene is fully loaded, all components initialized
    }
}
OnLoad tasks are awaited by the scene's loading system — the game won't start until all OnLoad tasks complete.
Was this helpful?