Search Unity

Unity #Protip: Super fast enter playmode times when working in DOTS

Discussion in 'Data Oriented Technology Stack' started by Joachim_Ante, Oct 8, 2020.

  1. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,159
    I noticed that not everyone who is using Entities for all simulation code in the game is also enabling fast enter play mode on their projects.

    You are wasting valuable time! Fortunately it's straightforward to fix.

    For reference: Enter Playmode on DOTS shooter is ~500ms... And you can have the same on your project today. Without the fast playmode enabled it takes around 5-10 seconds.

    Fast enter play-mode in Unity is not the default because most projects are game object based and game object based projects have a tendency to use tons of static variables for state. And doing that by default makes it so that a domain reload is required to reset all the static state before entering playmode.

    By design, everything we do in DOTS avoids this pattern. Multiple worlds, per world singletons etc.
    They exist so that it becomes trivial to turn on the faster enter play mode option.

    This is the recommended setting in a DOTS based project:
    upload_2020-10-8_10-52-42.png

    https://blogs.unity3d.com/2019/11/05/enter-play-mode-faster-in-unity-2019-3/

    If you are making a DOTS based project where all or most simulation code is written with entities or if you simply have no static variables in your project you rely on for persistent state, then you should enable it. I recommend doing this as the first thing when starting a project, so that you force yourself to not create any global static state at any point.

    In the future, we have more functionality coming that further improves iteration speed on top of this. But it all requires turning this option on first.
     
  2. WAYN_Games

    WAYN_Games

    Joined:
    Mar 16, 2019
    Posts:
    723
    Hi, What about "Unity" hybrid components, like Audio, VFX and others, are they compatible with that feature ?
     
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,159
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    9,039
    Thx Joachim for reminder. I implemented relevant changes recently, which improved entering play mode greatly for me.

    I think this link from a blog, is worth to be referenced here too
    https://forum.unity.com/threads/configurable-enter-play-mode.768689/
     
  5. adammpolak

    adammpolak

    Joined:
    Sep 9, 2018
    Posts:
    363
    Holy moly thank you! You got any other likely things I forgot that radically make my development experience better like this? (weird question I know but now I am wondering what else I am missing out on...)
     
  6. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,431
    @Joachim_Ante Don't miss the original enthusiasm that drives you.
    About fast enter play mode: Put videos about using this option because I'm scared to use it.
     
  7. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    685
    What is the recommended way to dispose IDisposables (e.g. NativeArray) with this feature enabled? Do we require to hook into EditorApplication.playModeStateChanged?

    Code (CSharp):
    1. class Example : IDisposable{
    2.  
    3.   private NativeArray<Entity> Entities;
    4.  
    5.   public Example(){
    6.     // How to correctly dispose this when exiting playmode?
    7.    /*
    8.      A Native Collection has not been disposed, resulting in a memory leak. Allocated from:
    9.      Unity.Collections.NativeArray`1:.ctor(Int32, Allocator, NativeArrayOptions)
    10.    */
    11.     Entities = new NativeArray<Entity>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
    12.   }
    13.  
    14.   public void Dispose()
    15.   {
    16.     Entities.Dispose();
    17.   }
    18. }
     
    adammpolak likes this.
  8. WAYN_Games

    WAYN_Games

    Joined:
    Mar 16, 2019
    Posts:
    723
unityunity