Prefabs¶
System · Prefabs · server and client scripts
Prefabs spawns copies of prefabs, inspects which prefab an entity came from, and resets edited copies back to their prefab defaults. A prefab is a saved entity tree exported to an .ldv file named after the prefab.
Spawn¶
Spawn creates a copy of the prefab named name, applies an optional table of root field overrides, and returns its root entity. Raises an error when no prefab with that name exists.
Effects
- On a client,
Spawnspawns only platform prefabs and raises an error for place prefabs, thoughExistsalso finds place prefabs there.
Example
Exists¶
Exists returns whether the place or the platform has a prefab named name.
Example
Of¶
Of returns the prefab name that entity was spawned from, or nil when the entity is not linked to a prefab.
Example
RevertAddedComponent¶
RevertAddedComponent removes a component handle that a script or Studio added to an entity in a prefab copy. To reset a component that came from the prefab, use RevertEntityOverride.
Example
RevertEntityOverride¶
RevertEntityOverride resets overridden components on entity back to the prefab's defaults. Pass an optional component handle to revert only that component, or omit it to revert every component shared with the prefab.
Effects
- On the root of the copy,
Name,Position,Rotation,LocalPosition,LocalRotation, andPivotkeep their values.