How to sync up created and destroyed gameobjects for late joining players
Options
I'm looking to create a networked scene where late players can join and sync up to the current world state. That would be tracking any previously instantiated game objects, updating their transform/rotation/scale, and any extra stats.
I'm looking for an outline of the steps rather than explicit code.
I've made one attempt at this so far and the best I got was for the masterclient to boot and run fine, and any joining client to join, sync fine with other players, but all instantiated gameobjects would get generated at the root of the scene (not under the correct parent), resulting in them updating their transform based off the world space, rather than parent space. They wouldn't have any mesh either, the only way I could detect them was to add in debug.drawline to show their current transform in the world.
Thanks for the help.
I'm looking for an outline of the steps rather than explicit code.
I've made one attempt at this so far and the best I got was for the masterclient to boot and run fine, and any joining client to join, sync fine with other players, but all instantiated gameobjects would get generated at the root of the scene (not under the correct parent), resulting in them updating their transform based off the world space, rather than parent space. They wouldn't have any mesh either, the only way I could detect them was to add in debug.drawline to show their current transform in the world.
Thanks for the help.
0
Best Answer
-
I figured out what I was looking for.
My solution was to have the masterclient run a function when they join.
This function setup the data for the gameobjects.
It then calledPhotonNetwork.InstantiateSceneObject("PrefabName", position, rotation, 0, data)
I added a function to the gameobject to initialise the included data.void OnPhotonInstantiate(PhotonMessageInfo info) { object[] data = this.gameObject.GetPhotonView().instantiationData; thisfloat = (float) data[0]; etc... }
The masterclient then goes on to control the gameobject AI.
With this I was able to have late joining players that synced up, as well as drop the masterclient so another player would inherit that role, all without any noticeable effect on the world.5
Answers
-
I suppose to ask a direct question on this:
If I instantiate a gameobject before a player joins, should that client also call the instantiate function to make it appear for them, or is there another procedure they should do?0 -
I figured out what I was looking for.
My solution was to have the masterclient run a function when they join.
This function setup the data for the gameobjects.
It then calledPhotonNetwork.InstantiateSceneObject("PrefabName", position, rotation, 0, data)
I added a function to the gameobject to initialise the included data.void OnPhotonInstantiate(PhotonMessageInfo info) { object[] data = this.gameObject.GetPhotonView().instantiationData; thisfloat = (float) data[0]; etc... }
The masterclient then goes on to control the gameobject AI.
With this I was able to have late joining players that synced up, as well as drop the masterclient so another player would inherit that role, all without any noticeable effect on the world.5