public sealed class NetworkSpawnerSpawns and despawns networked instances. Server-side.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
Instantiate here and the clients follow. A spawn puts a NetworkSpawn on the instance's root; the root is a replicated entity like any other, so the snapshot carries it out, and a client's spawn system builds the same prefab from the same id. Nothing here writes a packet — which is the point, because a spawn that travelled by its own route would need its own answer to interest, to loss, and to what a late joiner is owed, and the snapshot already has all three.
Despawn is the same trick backwards. Destroying the entity takes it out of what the interest resolver returns, and leaving interest already means "drop it" — so a client cannot tell destruction from walking over the horizon, and does not need to. What this adds is telling ReplicationServer to stop tracking the ids, which is memory rather than correctness.
Fields and properties (7)
public NetworkOwnership? OwnershipWho owns what. Optional; without it a spawn's owner is only on the wire.
public NetworkRulesRegistry? RulesWho may do what. Optional; without it the server may spawn and nobody else may.
public ReplicationServer? ReplicationThe replicator to tell about despawns, so it stops tracking them.
public SceneManager? ScenesThe scenes this peer has loaded. Optional; without it spawns belong to no scene.
public NetworkSceneMap? SceneIdsWhich networked scene each local one is. Optional, and needed with Scenes.
public long SpawnedCountHow many instances have been spawned.
public long DespawnedCountHow many have been despawned.
Methods (6)
public NetworkSpawner(NetworkPrefabRegistry prefabs, NetworkIdAllocator ids)Creates a spawner.
public bool MaySpawn(PlayerId requester)Whether a player may ask for a spawn at all.
public Entity Spawn(World world, string address, LocalTransform? at = null, SceneHandle scene = default(SceneHandle), PlayerId owner = default(PlayerId))Spawns an instance of a registered prefab.
public Entity Spawn(World world, NetworkPrefab prefab, LocalTransform? at = null, SceneHandle scene = default(SceneHandle), PlayerId owner = default(PlayerId))Spawns an instance of a prefab already looked up.
public int Despawn(World world, Entity root)Despawns an instance.
public int DespawnScene(World world, SceneHandle scene)Despawns every networked instance in a scene.
Used by (3)
- NetworkSpawnTestsVixen.Net.Engine.Tests
- PlayerSpawnerVixen.Net.Engine
- PlayerSpawnerTestsVixen.Net.Engine.Tests