Named
Overview
The Named component provides functionality for assigning, storing, and synchronating custom names to entities. It handles name selection from a pool of possible names, name assignment (with optional authorship tracking), and persistence across saves. When a name is set, it updates both the local entity state and the network replica for synchronization in multiplayer.
Dependencies & Tags
- Component Dependencies:
replica.named— Required for network replication of the name and author (viaself.inst.replica.named:SetName(...)).
- No explicit tag additions or removals.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | (inherited from constructor) | Reference to the owning entity instance. |
possiblenames | table (array of strings) | nil | Optional list of candidate names; used by PickNewName(). |
nameformat | string? | nil | Optional format string for processing self.name (e.g., "Mr. %s"). |
name | string? | nil | The resolved/custom name string. |
name_author_netid | number? | nil | The network user ID of the player who assigned the name (platform ID, not Kunai ID). |
Main Functions
DoSetName(self)
- Description: Applies the current name and author info to the entity and synchronizes it via the
replica.namedinterface. Handles optional string formatting viaself.nameformat. - Parameters:
self— TheNamedcomponent instance.
PickNewName(self)
- Description: Randomly selects a name from the
possiblenameslist (if defined and non-empty), then sets it viaDoSetName. - Parameters:
self— TheNamedcomponent instance.
SetName(self, name, author)
- Description: Explicitly sets the entity's name and optional author. If
nameisnil, reverts to the default name (e.g.,STRINGS.NAMES["PIGKING"]). Updates local state and replicates changes. - Parameters:
name(string?) — The desired name, ornilto reset to the default.author(Player?) — Optional player entity/string reference used to resolve the author's network ID viaTheNet:GetNetIdForUser().
OnSave(self)
- Description: Returns a serialization table containing name-related fields if a custom name exists; otherwise, returns
nil. - Parameters:
self— TheNamedcomponent instance.
- Returns:
table?— Table with keysname,nameformat,name_author_netid, ornil.
OnLoad(self, data)
- Description: Restores name-related state from saved data (e.g., after load), then applies the loaded name via
DoSetName. - Parameters:
data(table?) — Saved state object, expected to containname,nameformat, and/orname_author_netid.
Events & Listeners
None.