Spawner Class
Spawner can instantiate and destroy objects on all clients in the Room simultaneously.
Namespace: Alteruna.MultiplayerAssembly: Alteruna (in Alteruna.dll) Version: 2.0.1+a1176e08a0b4a6bfd8fefeddde6163a16d29e5ab
public class Spawner : CommunicationBridge
- Inheritance
- Object Object Component Behaviour MonoBehaviour CommunicationBridge Spawner

Here's an example of using the Spawner to spawn cubes and spheres using different positions and rotations. It also showcases how to despawn game objects.
public class MySpawner : MonoBehaviour
{
public Spawner spawner;
public GameObject cubePrefab;
private int _cubeIndex;
public GameObject spherePrefab;
private int _sphereIndex;
// Since we will create three cubes that we want at different positions and rotations, we create
// variables that hold that data.
private readonly Vector3[] _cubeSpawnPositions =
{
new Vector3(0, 0, 0),
new Vector3(1, 0, 1),
new Vector3(-1, 0, 1),
};
private readonly Vector3[] _cubeSpawnRotations =
{
new Vector3(0, 0, 0),
new Vector3(0, 45, 45),
new Vector3(0, 20, 50),
};
private GameObject _spawnedSphere;
private void Start()
{
// We add the prefabs to the SpawnableObjects list.
spawner.SpawnableObjects.Add(cubePrefab);
// We also set the index, based on the order we put the prefabs in the list.
_cubeIndex = 0;
spawner.SpawnableObjects.Add(spherePrefab);
_sphereIndex = 1;
}
public void SpawnSphereOnAllClients()
{
// We spawn the sphere prefab using its index in the SpawnableObjects array.
// Additionally, we store the spawned sphere so we can despawn it later.
_spawnedSphere = spawner.Spawn(_sphereIndex);
// Alternatively, we can spawn the prefab using its name.
// spawner.Spawn("Sphere");
}
public void SpawnCubesOnAllClients()
{
for(int i = 0; i < 3; i++)
{
// We spawn the cubes using different positions and rotations.
spawner.Spawn(_cubeIndex, _cubeSpawnPositions[i], _cubeSpawnRotations[i]);
}
}
public void DespawnSphereOnAllClients()
{
// We despawn the previously spawned sphere on all clients.
spawner.Despawn(_spawnedSphere);
}
}
| Despawn | Invoked when a GameObject has been despawned by a User in the Room. |
| Spawn(Int32) | Spawn an new game object from index for all Users in the Room. |
| Spawn(String) | Spawn a new object from name for all Users in the Room. |
| Spawn(Int32, Vector3) | Spawn an new game object from index for all Users in the Room with position. |
| Spawn(String, Vector3) | Spawn a new object from name for all Users in the Room with position. |
| Spawn(Int32, Vector3, Quaternion) | Spawn a new game object from index for all Users in the Room using position and eular angles rotation. |
| Spawn(Int32, Vector3, Vector3) | Spawn an new game object from index for all Users in the Room using position and rotation. |
| Spawn(String, Vector3, Quaternion) | Spawn a new object from name for all Users in the Room using position and rotation. |
| Spawn(String, Vector3, Vector3) | Spawn a new object from name for all Users in the Room using position and euler angles rotation. |
| Spawn(Int32, Vector3, Quaternion, Vector3) | Spawn an new object for all Users in the Room using position, rotation, and scale. |
| Spawn(Int32, Vector3, Vector3, Vector3) | Spawn an new game object from index for all Users in the Room using position, rotation, and scale. |
| Spawn(String, Vector3, Quaternion, Vector3) | Spawn a new object from name for all Users in the Room using position, rotation, and scale. |
| Spawn(String, Vector3, Vector3, Vector3) | Spawn an new object from name for all Users in the Room using position, euler angles rotation, and scale. |
| Start | |
| ForceSync | When true, spawn previously spawned objects on joining client(s). |
| OnObjectDespawn | Invoked before GameObject gets despawned by a User in the Room. |
| OnObjectSpawn | Invoked after GameObject has been spawned by a User in the Room. |
| SpawnableObjects | List of GameObjects which can be spawned during the game. |