Skip to main content

RespawnOnDestroy

A class in Root.Township, the global namespace.

Server: when a child entity is destroyed in play, respawns a saved copy after a random delay and parents it back under this entity.

Constructors​

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

Fields​

4 private and internal fields
MemberWhat it is
private float maximumTimeToRespawnLongest respawn delay in seconds.
private float minimumTimeToRespawnShortest respawn delay in seconds.
private Timeline.IEntry respawnEntryPending respawn on the timeline.
private SavableSavedDynamicObject respawnObjectSaved copy of the object to respawn. In this code it's only set from save data.

Methods​

MemberWhat it is
override void InitializeAsServer(SpawnData spawnData)Subscribes to the destroy event of every child entity.
3 private and internal methods
MemberWhat it is
private void CheckRespawn(NetworkEntity entity, bool isUnload)Schedules a respawn on the timeline when a child is destroyed, but not when it's only unloaded.
private void OnDestroy()Cancels a pending respawn.
private void Respawn()Spawns the saved object, initializes it as server, watches it again and parents it here.