Singingshelltrigger
Overview
This component monitors the entity's surroundings for nearby entities tagged with "singingshell" (and not "INLIMBO") within a fixed range, and invokes a custom _activatefn callback on each newly detected shell. It automatically starts/stops its update loop in response to death and resurrection events, ensuring activation logic only runs while the entity is alive.
Dependencies & Tags
- Component Requirements: None (uses only built-in engine APIs like
TheSim:FindEntitiesand component update infrastructure). - Tags Added:
"singingshelltrigger" - Tags Removed on Remove:
"singingshelltrigger" - Listened Events:
"death","respawnfromghost" - External Dependency Check: Verifies existence of
TheWorld.components.singingshellmanagerbefore starting updates.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
trigger_range | number | 4 | Radius (in units) within which to scan for singing shells. |
findentitiesfn | function | findentities (local closure) | Function used to locate entities matching shell criteria. |
updating | boolean | false | Tracks whether the component’s OnUpdate is currently scheduled. |
overlapping | table | {} | Tracks which entities are currently overlapping; keys are entity instances, values are true (first frame) or false (subsequent frames). |
Main Functions
StartUpdating()
- Description: Begins invoking
OnUpdateeach game tick by registering the component with the entity’s update manager. Ensures idempotency by only starting if not already updating. - Parameters: None.
StopUpdating()
- Description: Halts the
OnUpdateloop by unregistering the component from the entity’s update manager. Prevents unnecessary processing when inactive (e.g., on death). - Parameters: None.
OnUpdate()
- Description: Executes each tick while
updatingistrue. Clears stale overlap tracking, then scans for nearby singing shells and invokes_activatefn(v, self.inst)on newly detected shells. Maintains overlap state to differentiate first-frame detection from continued presence. - Parameters: None.
OnRemoveFromEntity()
- Description: Cleans up upon component removal: removes the
"singingshelltrigger"tag, and unregisters death/resurrection event callbacks. - Parameters: None.
Events & Listeners
- Listens to
"death"→ invokesondeath(inst), which callsStopUpdating(). - Listens to
"respawnfromghost"→ invokesonresurrect(inst), which callsStartUpdating().