Wake and 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.
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");
}
}