Enemies spawn point and synchronization
Options
3gogames
✭
Hi,
we've a map with many spawn points for player's enemies. These spawn points are controlled only by the Master Client and they instantiate the enemies by using PhotonNetwork.InstantiateSceneObject. In order to control the spawned entities, a spawn point must have a list of the created GameObjects.
We need to mantain that list updated on all clients, to have a consistent situation when the Master Client switch - if the current one leaves.
What is the suggested way to to this synchronization?
Thanks a lot for your help,
Devis
we've a map with many spawn points for player's enemies. These spawn points are controlled only by the Master Client and they instantiate the enemies by using PhotonNetwork.InstantiateSceneObject. In order to control the spawned entities, a spawn point must have a list of the created GameObjects.
We need to mantain that list updated on all clients, to have a consistent situation when the Master Client switch - if the current one leaves.
What is the suggested way to to this synchronization?
Thanks a lot for your help,
Devis
0
Comments
-
Hi,
You can handle OnPhotonInstantiate message to update objects lists on clients.
Each client gets this message on new object creation.0 -
Thanks!
This is perfect if I want to fill a global list of my spawned enemies (a single enemy, inside OnPhontonInstantiate can register itself on a dedicated EnemyManager).
But if I want to keep track of the enemies spawned by a single spawn point, how can I do? Maybe I can send an RPC with the photonViewId of the monster and the photonViewId of the spawn point...is it a valid solution?
Devis0 -
Yes, you can send RPCs with ViewIDs of objects in payload and retrieve objects later with PhtonView.Find()0
-
I've another question:
When I spawn a wave of enemies from a spawn point I call this method:public void SpawnEnemies() { if (PhotonNetwork.isMasterClient) { if (m_ActiveWave == null) return; for (int index = 0; index < m_ActiveWave.Length; ++index) { string prefabName = m_ActiveWave[index].name; GameObject enemy = PhotonNetwork.InstantiateSceneObject(prefabName, transform.position, Quaternion.identity, 0, null); PhotonView view = enemy.GetComponent<PhotonView>(); m_PhotonView.RPC("EnemySpawned", PhotonTargets.All, (int)view.viewID); } } }
and:[PunRPC] private void EnemySpawned(int i_ViewID) { PhotonView photonView = PhotonView.Find(i_ViewID); if (photonView != null) { m_SpawnedEnemies.Add(photonView.gameObject); } }
The RPC is called because I need to keep track of the enemies spawned by a specific spawn point.
If the MasterClient disconnects, is it possible that the InstantiateSceneObject command is delivered, but not the RPC? In that case, what can we do?
Thanks,
Devis0 -
Yes, it's possible but very unlikely to happen.
You need to hide/pause just created objects until RPC confirmation arrived. Discard such objects after timeout or in OnMasterClientSwitched handler. As I wrote earlier, you can use OnPhotonInstantiate handler to add such unassigned objects to the list.0 -
Sorry but I don't understand. I can't use OnPhotonInstantiate because I need to pass the PhotonView Id as parameter with a specific RPC.
Maybe an alternative could be manually instatiate objects, as explained here: http://doc-api.exitgames.com/en/onpremi ... neral.html
If a send an RPC with the photon view Id of the object to instantiate and the photon view Id of the spawn point, I can do both operations in a single method.
But how can I manually destroy a scene object instantiated with this procedure?
Thanks a lot,
Devis0 -
3gogames wrote:If the MasterClient disconnects, is it possible that the InstantiateSceneObject command is delivered, but not the RPC? In that case, what can we do?0