Search Unity

Network.Instantiate causes lag in-editor

Discussion in 'Multiplayer' started by returnString, Aug 29, 2012.

  1. returnString

    returnString

    Joined:
    Jul 10, 2010
    Posts:
    248
    Really bizarre issue here. I have some AISpawner instances that handle server-side instantiation of enemies. The code is incredibly simple, and works without a hitch across Windows, Mac, iOS and Android:

    Code (csharp):
    1. var ai = Network.Instantiate(AIPrefab, Vector3.zero, Quaternion.identity, 0) as GameObject;
    2. var controller = ai.GetComponent<AIController>();
    3. controller.Init(GetSpawnPosition());
    AIPrefab is an inspector variable, and GetSpawnPosition just grabs a random position from within the spawn area; Init just does some post-spawn setup. This is only ever called on the server.

    For some weird reason, this causes a good second's worth of lag, but only when I'm playtesting in the editor; works smoothly as expected even on mobile. I'm using Unity Free and the basic mobile licences, so I can't profile.

    Any thoughts? :)
     
  2. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    Is network debugging enabled? Also try hiding the inspector (put something else on a different tab, and switch to that tab) as it has a huge impact on performance.

    You can also use System.Diagnostics.Stopwatch to time regions of code and find out exactly which bit is being slow, e.g. is the lag occuring on the Instantiate call, or is it occuring at the end of the frame.
     
  3. returnString

    returnString

    Joined:
    Jul 10, 2010
    Posts:
    248
    Oh of course, network debugging :) Had it set to informational, totally forgot about the log overhead from that, particularly when I sent a few RPCs at once in other areas (and my own log callback contributes too). Cheers!