batchmode consumes 100% cpu

Hi,

I’ve built a dedicated unity server for my game that essentially just passes messages around to other clients and not much else. I know from reading around that using a unity build for this is a bit overkill but that’s what was decided.

My problem is that when running the application with batchmode it consumes 100% of the cpu but when I run it without batchmode it barely uses any.

I’ve limited the framerate of the server using Application.targetFrameRate to keep it locked at 60 fps and there are no graphical objects/cameras for the server, and no exceptions or other errors are showing up in my logs.

Does anyone know what could possibly be going on?

Thanks

I had the same problem and it seems it was associated to several unrelated problems.

  1. I was running an app that was built from a project that was created with an older 3.5 version of Unity and then upgraded several times as new Unity version were released. The solution for me was to use text format for metadata files (Edit->Project Settings->Editor->Asset Serialization->Force Text). Then I created a clean project and compared the files in Project Settings. Some of the options were missing in the old version or they didn’t contain all the data. For example: m_PerPlatformDefaultQuality in QualitySettings.asset didn’t contain a few platform definitions.

  2. Another problem was that one of my prefabs contained either an animation that had leftover curves which can be removed in Animation Editor or it was related to the material of that prefab which was a Substance material.

Which platform are you running on?

Also, targetFrameRate has no effect if you’re vsync is set to on (in quality settings). Change it to 0 and see if that helps.

Also try adding a manual framerate limiter that sleeps a thread, i.e.

  private float goalFPS = 30;
  private float millisecondsToWait = 0; 

  public void Update()
  {
    var overflow = 1.0/goalFPS - Time.deltaTime;

    if (overflow > 0.0)
        millisecondsToWait++;
    else
        millisecondsToWait--;
    
    Thread.Sleep( (int)Mathf.Clamp(millisecondsToWait, 0.0f, 1.0f/goalFPS * 1000.0f) ); // clamp for sanity
  }