ISpawnable - jimdroberts/FishMMO GitHub Wiki
ISpawnable is an interface for FishMMO that defines the contract for spawnable entities managed by an ObjectSpawner. It provides access to the spawner, settings, network object, unique ID, and despawn logic, enabling consistent management and network synchronization of dynamic entities in the game world.
-
ObjectSpawner ObjectSpawner { get; set; }
The ObjectSpawner responsible for spawning and managing this entity.
-
SpawnableSettings SpawnableSettings { get; set; }
The settings used to configure this spawnable entity.
-
NetworkObject NetworkObject { get; }
The network object associated with this entity for network synchronization.
-
long ID { get; }
The unique identifier for this spawnable entity.
-
void Despawn()
Despawns the entity, removing it from the game world and network.
- Implement the ISpawnable interface in your entity class.
- Provide logic for property accessors and the Despawn method.
- Register the entity with an ObjectSpawner for management and network synchronization.
// Example 1: Implementing ISpawnable in a custom entity
public class MySpawnableEntity : MonoBehaviour, ISpawnable
{
public ObjectSpawner ObjectSpawner { get; set; }
public SpawnableSettings SpawnableSettings { get; set; }
public NetworkObject NetworkObject { get; private set; }
public long ID { get; private set; }
public void Despawn()
{
// Custom despawn logic
}
}
// Example 2: Spawning and despawning an entity
objectSpawner.Spawn(mySpawnableEntity);
mySpawnableEntity.Despawn();
- Always implement all properties and methods defined by the interface for consistent behavior.
- Use the ID property to uniquely identify and track spawnable entities.
- Ensure Despawn properly cleans up the entity from both the game world and network.