Photon Instantiate Sync
Hello Guys, I have a full match3 game working offline mode and Im making it to work online multiplayer on Photon.
I have only 2 players, the master and the client
Only the Master will spawn 100 cubes in the screen with Random.Range code to set randon textures on the cubes.
It works offline and online by Photon and the client must see then by PhotonView. Its ok too.
The client only gets +- the first 10 textures correctly and later he losts the logic of the script and the rest of the cubes will have different textures from the Master.
I dont know what to do. If I spawn just a few like 10, the client take all correctly. More than this he lost himself.
I need some help.
And sorry about my english.
I have only 2 players, the master and the client
Only the Master will spawn 100 cubes in the screen with Random.Range code to set randon textures on the cubes.
It works offline and online by Photon and the client must see then by PhotonView. Its ok too.
The client only gets +- the first 10 textures correctly and later he losts the logic of the script and the rest of the cubes will have different textures from the Master.
I dont know what to do. If I spawn just a few like 10, the client take all correctly. More than this he lost himself.
I need some help.
And sorry about my english.
0
Best Answer
-
Hi @GuyGardner,The client only gets +- the first 10 textures correctly and later he losts the logic of the script and the rest of the cubes will have different textures from the Master.
If both clients are using Random.Range to select a texture, you will of course have different results. When having this online you have to synchronize the texture selected by the MasterClient in order to have the other client apply the same texture. Using different prefabs is also an option you have.
If you continue using a single prefab, you can take a look at the InstantiationData, which is the last parameter of the Instantiate as well as the InstantiateSceneObject function. Using this you can set an int value for example in order to describe which texture a client should apply to the object. You can access this data for example in the Start function of a certain object by usingGetComponent<PhotonView>().instantiationData
.5
Answers
-
Hi @GuyGardner,The client only gets +- the first 10 textures correctly and later he losts the logic of the script and the rest of the cubes will have different textures from the Master.
If both clients are using Random.Range to select a texture, you will of course have different results. When having this online you have to synchronize the texture selected by the MasterClient in order to have the other client apply the same texture. Using different prefabs is also an option you have.
If you continue using a single prefab, you can take a look at the InstantiationData, which is the last parameter of the Instantiate as well as the InstantiateSceneObject function. Using this you can set an int value for example in order to describe which texture a client should apply to the object. You can access this data for example in the Start function of a certain object by usingGetComponent<PhotonView>().instantiationData
.5 -
Thanks Christian, working with InstantiationData works for me.0