Ghostbabysitter
Based on game build 714014 | Last updated: 2026-03-03
Overview
Ghostbabysitter tracks which ghosts an entity is currently "babysitting"—i.e., monitoring or managing. It maintains a simple dictionary of ghost references, adds/removes the inactive and activatable_forceright tags on the owner entity based on babysitting state, and ensures proper persistence across saves/loads. The component also supports optional per-frame updates via an optional updatefn callback, which is invoked during OnUpdate while babysitting at least one ghost.
Usage example
local inst = CreateEntity()
inst:AddComponent("ghostbabysitter")
local ghost = GetSomeGhostInstance()
inst.components.ghostbabysitter:AddGhost(ghost)
-- Optional: set a custom update function
inst.components.ghostbabysitter.updatefn = function(owner, babysitter, dt)
-- custom logic here
end
-- Later, stop babysitting
inst.components.ghostbabysitter:RemoveGhost(ghost)
Dependencies & tags
Components used: None identified
Tags: Adds/removes inactive and activatable_forceright on the owning entity.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | assigned in constructor | Reference to the entity that owns this component. |
inactive | boolean | true | Indicates whether the component is currently inactive (i.e., not babysitting any ghosts). |
forcerightclickaction | boolean | false | Controls whether activatable_forceright tag is applied. |
babysitting | table | {} | Dictionary mapping ghost entity references to true. |
updatefn | function | nil | Optional callback (owner, self, dt) => void, invoked each frame while babysitting is non-empty. |
Main functions
AddGhost(ghost)
- Description: Begins babysitting the specified ghost, adding it to the internal tracking table and starting the component's update loop on the entity.
- Parameters:
ghost(Entity) — the ghost entity to track. - Returns: Nothing.
RemoveGhost(ghost)
- Description: Stops babysitting the ghost and removes it from tracking. If no ghosts remain, stops the update loop.
- Parameters:
ghost(Entity) — the ghost entity to stop tracking. - Returns: Nothing.
IsBabysittingGhost(ghost)
- Description: Checks whether the given ghost is currently being babysat.
- Parameters:
ghost(Entity) — the ghost to check. - Returns:
trueifghostis inbabysitting; otherwisenil. - Error states: Returns
nilif the ghost is not being babysat.
OnUpdate(dt)
- Description: Called each frame while the component is active (i.e., while
babysittingis non-empty). Invokesupdatefnif set. - Parameters:
dt(number) — delta time in seconds. - Returns: Nothing.
- Error states: No effect if
updatefnisnil.
OnSave()
- Description: Serializes the component's state for saving.
- Parameters: None.
- Returns:
data(table),ents(table of GUIDs) —data.babysittingcontains a list of GUIDs of babysat ghosts;entscontains the same list for dependency resolution.
LoadPostPass(newents, savedata)
- Description: Restores ghost references after loading is complete. Notifies each ghost that it is being babysat.
- Parameters:
newents(table) — map of GUID → entity for all loaded entities;
savedata(table) — data fromOnSave, includingbabysittinglist of GUIDs. - Returns: Nothing.
OnRemoveFromEntity()
- Description: Cleanup handler called when component is removed from its entity. Ensures all tracking tags are removed.
- Parameters: None.
- Returns: Nothing.
GetDebugString()
- Description: Returns a simple debug representation of the component’s
inactivestate. - Parameters: None.
- Returns: string —
"true"or"false".
Events & listeners
- Listens to: None
- Pushes:
set_babysitter— fired on each ghost entity when it is assigned a babysitter duringLoadPostPass.