SpawnBuried
A class in Root.Township, the global namespace.
A dig spot that holds a buried item: the server spawns an item under it, keeps it kinematic and parented, and digging pulls it up. Saved with the item as a child.
- Listed in Global namespace: S
- Inherits or implements
GeneratedNetworkEntityBehaviour,ISavable<SpawnBuriedSaveData>,ISavableSave<SpawnBuriedSaveData>,ISavableSaveBase,IDigable - Derived types
SpawnBuriedSaveData
Constructors
| Member | What it is |
|---|---|
SpawnBuried() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
5 private and internal fields
| Member | What it is |
|---|---|
private PullPickup pullUpPickup | The pull handle that lifts the item out when dug. |
private Distribution spawnDistribution | Weighted set of prefabs to bury. Used before spawnPrefab if set. |
private Interactable spawnedItem | The buried item's interactable. |
private NetworkPrefab spawnPrefab | Fixed prefab to bury when there is no distribution. |
private MethodSync syncTarget | Method sync used to send the buried entity's ID. |
Methods
| Member | What it is |
|---|---|
override void Initialize() | Sets up the message sync that tells clients which entity is buried here. It reuses the PotionCapRemoved message type. |
override void InitializeAsServer(SpawnData spawnData) | Server: spawns an item if none was loaded. |
override void OnConnected(Player player) | Server: sends the buried item's ID to a player who joins. |
void ReleaseSpawned() | Frees the item (unparents, re-enables physics, restores save mode) and destroys the dig spot. |
void Spawn() | Server: spawns a random prefab from spawnDistribution, or spawnPrefab if there is none. |
protected override void Generate(SpawnData spawnData) | Spawns the buried item when the spot is first generated. |
7 private and internal methods
| Member | What it is |
|---|---|
private void IDigable.Dig(float diggingDamage) | Called by digging tools. Pulls the buried item up through pullUpPickup. |
private void IDigable.DiggingToolHit() | Empty. |
private void OnDrawGizmos() | Draws a small green sphere at the spot. |
private void RegisterChild(NetworkPrefab prefab, NetworkEntity parent, int childIndex) | Load callback: takes the saved child pickup as the buried item. |
private void RegisterEntity(NetworkEntity spawnedBehaviour) | Parents the spawned entity here, registers it as the buried item and, on a real server, syncs it to the chunk. |
private void RegisterPickup() | Makes the item a saved child, freezes its physics, applies its BuriedItemTag offset and pull distance, and hands it to the pull pickup. |
private void SyncTarget(IPlayer player, Stream stream) | Writes or reads the buried entity's ID; clients wait for that entity to spawn then register it. |