SceneSpawner
Last updated
Last updated
You must create separate GameObjects for different room agent components.
SceneSpawner instantiates and destroys Networked GameObject in a Scene(GameObjects that have a Network ID components).
The SceneSpawner fetches spawn history in its Start() method and calls the OnReady event after that.
If a client was not connected to the game servers when a SceneSpawner's Start() method was called, the SceneSpawner will skip the fetching and it will not invoke the OnReady event.
Name | Function |
Spawner Id | Used to identify a SceneSpawner. Make sure you give different Spawner Id to different SceneSpawners because SceneSpawner stores important GameObject Spawn History of a scene. GameObject Spawn History is used to restore GameObjects when players disconnected and reconnected to a game. |
Spawn Points | A list of transforms which are used as the initial position and rotation of Networked GameObjects. |
Player Prefabs | A list of prefabs for player controlled GameObjects. |
Non-player prefabs | A list of prefabs for non-player controlled GameObjects. |
Event | Description |
OnReady | Invoked when the SceneSpawner finished fetching its spawn history from the game servers and is ready to use. |
OnHostReady | Invoked when the SceneSpawner finished fetching its spawn history from the game servers and is ready to use. Only invoked on the room's host client. |
Name | Description |
NumberOfPlayerPrefabs | Number of player prefabs |
NumberOfNonPlayerPrefabs | Number of non-player prefabs |
NumberOfSpawnPoints | Number of spawn points |
SpawnerId (BETA) | Gets the SpawnerId assigned to the SceneSpawner |
Name | Description |
SpawnForPlayer(int, int) | Spawn a player controlled networked GameObject with the specified prefabIndex and spawnPointIndex. |
SpawnForPlayer(int, Vector3) | Spawn a player controlled networked GameObject with the specified prefabIndex and position. |
SpawnForNonPlayer(int, int) | Spawn a non-player controlled networked GameObject with the specified prefabIndex and spawnPointIndex. |
SpawnForNonPlayer(int, Vector3) | Spawn a non-player controlled networked GameObject with the specified prefabIndex and position. |
DestroyGameObject(GameObject) | Destroy the specified gameObject. If the gameObject has a NetworkID component, the remote duplicates of the gameObject will be destroyed as well. |
PlayerFinishedSceneSetup() | Set FinishedSceneSetup to true for the local client. |
HostFinishedSceneSetup() | Set FinishedSceneSetup to true for the room host client. |
This example demonstrates how to spawn a player controlled GameObject. As shown in the screenshot, the SceneSpawner has 1 PlayerPrefab and 4 SpawnPoints.