Skip to main content

Shedder

Overview

The Shedder component manages periodic or one-time spawning of items (e.g., shedded body parts) from an entity. It supports both single and batch shedding, optionally applying physics velocity to spawned items to simulate scattering. This is typically used for creatures like Bearger that shed physical objects (e.g., fur, chitin) during seasonal transitions or other game events.

Dependencies & Tags

  • Relies on the presence of Transform and Physics components on the parent entity (self.inst) for position and velocity operations.
  • Automatically registers a cleanup handler via Shedder.OnRemoveFromEntity = Shedder.StopShedding, ensuring shedding stops when the component is removed from the entity.

Properties

PropertyTypeDefault ValueDescription
instEntitynil (assigned by constructor)Reference to the host entity.
shedItemPrefabstring?nilPrefab name of the item to spawn when shedding occurs.
shedHeightnumber6.5Vertical (Y-axis) position offset where shed items appear.
shedTaskGorillaTask?nilReference to the recurring periodic task; nil if shedding is inactive.

Main Functions

StartShedding(interval)

  • Description: Starts a recurring task that triggers shedding at a fixed time interval. Cancels any existing shedding task first.
  • Parameters:
    • interval (number?, optional): Time in seconds between sheds. Defaults to 60.

StopShedding()

  • Description: Cancels any active periodic shedding task and clears the task reference.

DoSingleShed()

  • Description: Spawns a single item at the entity’s current position, offset vertically by shedHeight and horizontally by a small random amount (±0.5 units). Returns the spawned item instance or nil if no item could be spawned.
  • Parameters: None.

DoMultiShed(max, random)

  • Description: Spawns multiple items (max count or random count if random is true) using DoSingleShed, then applies outward physics velocity to each spawned item to scatter them radially.
  • Parameters:
    • max (number): Maximum number of items to shed.
    • random (boolean): If true, the actual number of items shed is a random integer between 1 and max.

Events & Listeners

  • Listens to entity removal via Shedder.OnRemoveFromEntity, which is set to Shedder.StopShedding to ensure cleanup when the component is removed.