Update called before Start using Mirror

In my project when a client connects the server spawns some characters and initialises a TurnsManager object (in this order).
These characters have a health component which is initialised in their Start method.
The TurnsManager in its Update, if it has been initialised, picks one of the characters for the next turn.
The problem is when this happens, the spawned character’s Health hasn’t gone through its Start yet, which confuses me as TurnsManager.Update should not be called before Health.Start.

My assumption is the characters are spawned while the client is already going through Update, so TurnsManager.Update is already “queued”, and Unity doesn’t stop Updates to go back and run Start on objects that have just been added. Is this what is happening?

This was an issue for Unet, and there were threads on it, though I can’t find them at the moment. Mirror is a fork of Unet, so may have inherited this issue (I don’t actually use Mirror, so can’t say if this is the case). My 2 workarounds when I was using Unet:

  1. set an initialized bool in Start which I would check for in Update, then run the initialization code from Update if not already set
  2. or check everywhere to make sure things are initialized before using them, and either initialize them there or just exit out of the method until Start gets called and things get initialized
1 Like