Use Lifecycle Hooks
Control when and how your component code runs
Quick Start
import { Behaviour } from "@needle-tools/engine";
export class MyComponent extends Behaviour {
// Called when component is created
awake() {
console.log("Component created!");
}
// Called first frame after creation
start() {
console.log("Component started!");
}
// Called every frame
update() {
console.log("Frame update");
}
// Called when destroyed
onDestroy() {
console.log("Component destroyed");
}
}Lifecycle Methods Overview
Method
When Called
Common Uses
Initialization: awake()
Cache Component References
Initialize Variables
Start Logic: start()
Use Other Components
Start Coroutines
Every Frame: update()
Movement
Input Handling
Rotation
Late Update: lateUpdate()
Camera Following
Billboard Effect
Enable/Disable: onEnable() & onDisable()
Event Subscriptions
Pause/Resume
Cleanup: onDestroy()
Resource Cleanup
Remove Global References
Execution Order
Advanced: earlyUpdate()
Advanced: onBeforeRender() & onAfterRender()
Update Shader Uniforms
Gather Statistics
Performance Best Practices
✅ DO
❌ DON'T
Complete Example: Health System
Next Steps
Last updated