Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Client initial state function call order

Discussion in 'Multiplayer' started by YondernautsGames, Jul 7, 2017.

  1. YondernautsGames

    YondernautsGames

    Joined:
    Nov 24, 2014
    Posts:
    352
    Hi there

    Just wanting to check something quickly:

    When a client joins a game in progress, are all objects synced before OnStartClient is called, or or is each object synced and started individually?

    From the manual:
    What I'm trying to do:
    I'm using an MVC setup for some of my game objects. I attach a model to a view using a SyncVar of NetworkInstanceId type. There is then a hook that resolves that to a reference to a specific behaviour that is stored locally, and then grabs some data to display. All that data is stored as SyncVars on the model. Thing is, when I call the hook from OnStartClient() on the view, it grabs the behaviour reference fine, but the data on the model doesn't seem to have synced yet. Could it be that the model object has not synced its SyncVar values before OnStartClient is called on the view?

    It makes most sense to me that the two things (syncing and starting) would be done in completely separate passes almost like awake and start on normal behaviours. The manual hints at that, but I can't see a definite answer and I've not had time to dig through all the source in Unity's BitBucket to try and track this down.

    Can anybody give me a definitive answer on this? Is sync and OnStartClient done in separate passes for all objects, or is it just sequential per object?

    Thanks
     
  2. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    It only makes sense to me that all syncvars gets sent over, and then onStartClient is called on all objects acording to the script execution order. I am not 100% sure of this, but It makes sense that way.
     
  3. YondernautsGames

    YondernautsGames

    Joined:
    Nov 24, 2014
    Posts:
    352
    Hey. Just to follow up in case someone else has this question, it does seem like that's the desired behaviour of sync all before start is what happens. I was having an issue with my SyncVars behaving differently on host vs client, but it was due to my own use, not the underlying system.