Highlightchild
Overview
This component allows an entity to maintain a highlight association with another entity (its "owner"). When set, the owned entity is added to the owner's highlightchildren list and receives visual highlighting; when the association is removed, it is removed from that list and its highlight state is cleared. The component also supports network synchronization of the owner reference for non-dedicated clients.
Dependencies & Tags
- Component Usage: None explicitly added to the host instance (
inst). - Tags: None identified.
- Network Usage: Uses
net_entityfor synchronization ofsyncowneron the master simulation (ifinst.Networkis available).
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | nil (assigned in constructor) | Reference to the entity that owns this component. |
owner | Entity? | nil | Current owner entity; nil means no active owner. |
syncowner | net_entity? | nil | Network sync object for the owner reference; only created if inst.Network ~= nil. |
onchangeownerfn | function? | nil | Optional callback function invoked after owner changes. |
Main Functions
OnRemoveEntity()
- Description: Cleans up the component's association when the entity is removed: removes
self.instfrom the current owner'shighlightchildrenarray (if any owner exists). - Parameters: None.
SetOwner(owner)
- Description: Sets the owner of this entity. If network sync is available, it updates the synced owner value and triggers
OnChangeOwner. This ensures consistency between master and clients. - Parameters:
owner(Entity?): The new owner entity, ornilto clear the owner association.
SetOnChangeOwnerFn(fn)
- Description: Registers a callback to be invoked whenever the
ownerchanges (i.e., insideOnChangeOwner). Useful for custom logic (e.g., updating UI or gameplay state). - Parameters:
fn(function?): A function with signaturefn(inst, owner); can benilto clear.
OnChangeOwner(owner)
- Description: Core logic to update the highlight association. On non-dedicated servers:
- Clears highlighting on the old owner (if any) by removing
self.instfrom the previous owner’shighlightchildrenlist and resetting the animation highlight color. - Adds
self.instto the new owner’shighlightchildrenlist (creating the list if needed). - Sets
self.ownerto the new value. - Invokes the
onchangeownerfncallback if present.
- Clears highlighting on the old owner (if any) by removing
- Parameters:
owner(Entity?): The new owner entity, ornil.
Events & Listeners
- Listens for
"syncownerdirty"event on the client (viainst:ListenForEvent) to re-synchronize the owner when the synced network value updates. The listener (OnSyncOwnerDirty) callsself:OnChangeOwner(self.syncowner:value()). - Pushes no custom events.