Skip to main content

SetPiece

A class in Root.Township, the global namespace.

A saved group of networked objects (SetPieceData) placed as one. On the server it spawns the group as children, then frees them into the chunk and destroys itself; in the editor it can store or ghost-preview the group.

Constructors​

MemberWhat it is
SetPiece()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

3 private and internal fields
MemberWhat it is
private SetPieceData dataThe set piece asset with the saved objects. Cleared on the server after spawning.
private SetPieceData oldDataThe last data seen by OnValidate, to spot changes.
private SaveMode saveModeSave mode passed when loading the objects. Default Ignore.

Methods​

MemberWhat it is
void ClearPieceInEditor()Editor: destroys all child objects.
void GhostPieceForEditor()Editor: loads the data, copies its renderers as ghosts, removes the real objects and keeps the ghosts as a preview.
override void InitializeAsServer(SpawnData spawnData)Server: loads the stored objects into the entity, clears data and waits to be added to a chunk.
void StorePieceInEditor()Editor: saves the children into the data. It destroys this component first and re-adds it with the data.
void StorePieceInEditorWithoutDestroy()Editor: saves the children into the data and keeps the component.
6 private and internal methods
MemberWhat it is
private void AddedToChunk(Chunk chunk)Server: once in a chunk, moves every child entity out to the parent, sets them to save on their own, then scene-destroys the set piece.
private static GameObject ApplyGhostingEffectToRenderer(Renderer renderer)Editor: makes a hidden, unsaved copy of a renderer with the same mesh and materials for previewing.
private void OnValidate()Editor: refreshes the ghost preview when data changes, stops children from saving into the scene, and names the object after the data.
private void PrepareNetworkPrefabSaveMode()Sets every child network prefab to save as a child of the set piece.
private void Save()Stores the entity and its children into data.DynamicData.
private void UpdateComponentDataReference()Puts data on the object's SetPiece, adding one if missing.