SushiEngine::Simulation::IEntityBehavior
on_enable
Message: the engine calls this function.
virtual void on_enable(IWorldEditor &world, EntityId id)Parameters
| Name | Type | Description |
|---|---|---|
world | IWorldEditor & | |
id | EntityId | This instance's own entity. |
Description
Runs after on_spawn on a hierarchy-enabled entity, and each time the entity becomes hierarchy-enabled again.
Example
class Stopwatch : public SushiEngine::Simulation::IEntityBehavior
{
public:
void on_enable(SushiEngine::Simulation::IWorldEditor& world,
SushiEngine::Simulation::EntityId id) override
{
lap_seconds_ = SushiEngine::Scalar(0);
}
void on_update(SushiEngine::Simulation::IWorldEditor& world,
SushiEngine::Simulation::EntityId id,
const SushiEngine::Simulation::TickContext& context) override
{
lap_seconds_ += context.delta_seconds;
}
void on_disable(SushiEngine::Simulation::IWorldEditor& world,
SushiEngine::Simulation::EntityId id) override
{
total_seconds_ += lap_seconds_;
}
void on_destroy(SushiEngine::Simulation::IWorldEditor& world,
SushiEngine::Simulation::EntityId id) override
{
SE_LOG_INFO(K_STOPWATCH_LOG_CATEGORY, "enabled for {} s", total_seconds_);
}
private:
SushiEngine::Scalar lap_seconds_ = SushiEngine::Scalar(0);
SushiEngine::Scalar total_seconds_ = SushiEngine::Scalar(0);
};

