> For the complete documentation index, see [llms.txt](https://kinematicsoup.gitbook.io/reactor/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinematicsoup.gitbook.io/reactor/examples/sleep_events.md).

# Sleep Events

## Summary

Shows how to use event handlers to track entity wake/sleep state changes during the PhysX simulation.

## Description

Entity `OnWake` and `OnSleep` events fire when an entity wakes up (starts moving) or falls asleep (stops moving) in the physics system. These events only fire for non-kinematic non-static physics entities. When an entity spawns, it will fire either `OnWake` or `OnSleep` depending on whether it starts in the wake or sleep state. The following script shows how to listen for `OnWake` and `OnSleep` events.

```c#
using KS.Reactor.Server;
using KS.Reactor;

public class sWakeSleepListener : ksServerEntityScript
{
    public override void Initialize()
    {
        Entity.OnWake += OnWake;
        Entity.OnSleep += OnSleep;
    }
    
    public override void Detached()
    {
        Entity.OnWake -= OnWake;
        Entity.OnSleep -= OnSleep;
    }

    private void OnWake()
    {
        ksLog.Info(this, "on wake");
    }

    private void OnSleep()
    {
        ksLog.Info(this, "on sleep");
    }
}
```
