Generate a random in start and sync across network.

My problem is, I want to generate a random number in Start and sync it across network to be used as spawn position. I have seen that only one of the players should generate that number and others should use it. But the issue is, I have to spawn in Start so when one of the players can enter the condition with generates random, others don't. So the default value of interger is used for them. Any workaround will be appreciate.

Comments

  • Hi @Hasnain,

    one player can generate a random number and store this value in the Custom Room Properties. Those are automatically synchronized on all clients. When the Custom Room Properties are updated, OnRoomPropertiesUpdate(Hashtable propertiesThatChanged) is called. Whenever it is called, each client can check, if the random number was set. If so, each client can spawn his object.
  • This looks like a good solution but the issue persists i.e instantiation happens in Awake for all the players so the number generation happens just before it and other players don't get a chance to use updated variable.
  • Use the Awake function only on the MasterClient in order to generate a random number and store it in the Custom Room Properties. Then let each client wait until they receive the updated Custom Room Properties (the above mentioned callback). Inside this callback, each client can instantiate his object by using the synchronized random number.
Sign In or Register to comment.