Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

How to add multiple worlds to player loop for Tiny/ DOTS Runtime?

Discussion in 'Project Tiny' started by SINePrime, Feb 25, 2021.

  1. SINePrime

    SINePrime

    Joined:
    Jan 24, 2019
    Posts:
    54
    I need multiple worlds in my Tiny project and have written an ICustomBootstrap. However, I don't see any documentation nor forum posts on how to add a new world to the player loop in Tiny/ DOTS runtime. The suggested way of using ScriptBehaviourUpdateOrder only works for the classic Unity runtime.

    How do I achieve multiple worlds in the DOTS Runtime?
     
  2. SINePrime

    SINePrime

    Joined:
    Jan 24, 2019
    Posts:
    54
    So I did some poking around in the DOTS Runtime code, and it looks like the DOTS Runtime does not support multiple worlds at all.

    But I found a very quick workaround by changing the main Update method:
    com.unity.dots.runtime@0.32.0-preview.54\Unity.Tiny.UnityInstance\UnityInstance.cs
    Code (CSharp):
    1.  
    2.         public bool Update(double timestampInSeconds)
    3.         {
    4.             var shouldContinue = true;
    5.  
    6.             if (m_BootPhase == BootPhase.Running)
    7.             {
    8.                 switch (m_RunState)
    9.                 {
    10.                     case RunState.Resuming:
    11.                         m_RunState = RunState.Running;
    12.  
    13.                         m_StartTimeInSeconds = timestampInSeconds - m_ElapsedTimeInSeconds;
    14.                         m_PreviousElapsedTimeInSeconds = m_ElapsedTimeInSeconds;
    15.                         goto case RunState.Running;
    16.  
    17.                     case RunState.Running:
    18.                         ComputeTime(timestampInSeconds);
    19.                         *m_TimeData = new TimeData(
    20.                             elapsedTime: m_ElapsedTimeInSeconds,
    21.                             deltaTime: (float)m_DeltaTimeInSeconds);
    22.  
    23.                         DotsRuntime.UpdatePreFrame();
    24.  
    25.                         // ORIGINAL CODE
    26.                         // m_World.Update();
    27.                         // shouldContinue = !m_World.QuitUpdate;
    28.  
    29.                         // ~CUSTOM~ CODE
    30.                         foreach (var iWorld in World.All)
    31.                         {
    32.                           iWorld.Update();
    33.                           shouldContinue &= !iWorld.QuitUpdate;
    34.  
    35.                           if(!shouldContinue) break;
    36.                         }
    37.  
    38.                         DotsRuntime.UpdatePostFrame(shouldContinue);
    39.                         break;
    40.                 }
    41.             }
    42.