Search Unity

I created this video guide to help explain Unity ECS

Discussion in 'Entity Component System' started by charlesamat, Apr 2, 2018.

  1. charlesamat

    charlesamat

    Joined:
    Feb 5, 2014
    Posts:
    66
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    I have updated the docs with info about the ComponentSystem being auto-created & fixed the freaking code example on intro page... Oops sorry, no idea how that happened... Will be in the next ECS release.
     
    Afonso-Lage, FROS7 and junaidmalikn2o like this.
  3. SubPixelPerfect

    SubPixelPerfect

    Joined:
    Oct 14, 2015
    Posts:
    224
    Thank you!

    Is it possible to disable automatic creation of default world ?
    I'd like to go "all manual" way without any magic auto include of all systems...
     
  4. MichalBUnity

    MichalBUnity

    Unity Technologies

    Joined:
    May 9, 2016
    Posts:
    18
    The automatic creation is done in AutomaticWorldBootstrap.cs in the com.unity.entities package.

    Basically the file looks like this

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3.  
    4. namespace Unity.Entities
    5. {
    6. #if !UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP
    7.     static class AutomaticWorldBootstrap
    8.     {
    9.         [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    10.         static void Initialize()
    11.         {
    12.             DefaultWorldInitialization.Initialize("Default World", false);
    13.         }
    14.     }
    15. #endif
    16. }
    17.  
    So to disable automatic creation just make sure to set the define UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP.

    Then all you need to do is create your world (line 30 below) and make sure Unity knows about it (line 59 below), and dont forget to make sure you also clean up on DomainReload (line 38 below). To see how this is done check DefaultWorldInitialization.cs below

    Code (CSharp):
    1.  
    2. using System;
    3. using System.Linq;
    4. using UnityEngine;
    5.  
    6. namespace Unity.Entities
    7. {
    8.     static class DefaultWorldInitialization
    9.     {
    10.         static void DomainUnloadShutdown()
    11.         {
    12.             World.DisposeAllWorlds();
    13.             ScriptBehaviourUpdateOrder.UpdatePlayerLoop();
    14.         }
    15.  
    16.         static void GetBehaviourManagerAndLogException(World world, Type type)
    17.         {
    18.             try
    19.             {
    20.                 world.GetOrCreateManager(type);
    21.             }
    22.             catch (Exception e)
    23.             {
    24.                 Debug.LogException(e);
    25.             }
    26.         }
    27.  
    28.         public static void Initialize(string worldName, bool editorWorld)
    29.         {
    30.             var world = new World(worldName);
    31.             World.Active = world;
    32.  
    33.             // Register hybrid injection hooks
    34.             InjectionHookSupport.RegisterHook(new GameObjectArrayInjectionHook());
    35.             InjectionHookSupport.RegisterHook(new TransformAccessArrayInjectionHook());
    36.             InjectionHookSupport.RegisterHook(new ComponentArrayInjectionHook());
    37.  
    38.             PlayerLoopManager.RegisterDomainUnload (DomainUnloadShutdown, 10000);
    39.  
    40.             foreach (var ass in AppDomain.CurrentDomain.GetAssemblies())
    41.             {
    42.                 var allTypes = ass.GetTypes();
    43.  
    44.                 // Create all ComponentSystem
    45.                 var systemTypes = allTypes.Where(t =>
    46.                     t.IsSubclassOf(typeof(ComponentSystemBase)) &&
    47.                     !t.IsAbstract &&
    48.                     !t.ContainsGenericParameters &&
    49.                     t.GetCustomAttributes(typeof(DisableAutoCreationAttribute), true).Length == 0);
    50.                 foreach (var type in systemTypes)
    51.                 {
    52.                     if (editorWorld && type.GetCustomAttributes(typeof(ExecuteInEditMode), true).Length == 0)
    53.                         continue;
    54.                      
    55.                     GetBehaviourManagerAndLogException(world, type);
    56.                 }
    57.             }
    58.  
    59.             ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
    60.         }
    61.     }
    62. }
     
  5. SubPixelPerfect

    SubPixelPerfect

    Joined:
    Oct 14, 2015
    Posts:
    224
    Awesome, thank you
     
  6. charlesamat

    charlesamat

    Joined:
    Feb 5, 2014
    Posts:
    66
    Great! The auto-creation info will be perfect for my upcoming vid on Hybrid ECS vs Pure ECS.
     
  7. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    Is it possible to create a separate world for normal objects as well?
    So we could have two simulations (server-objects and client-objects) in the same process for networking tests, without having to essentially share objects (as it currently is with UNET)
     
  8. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Will there be UI improvements so these systems show up in the editor and could be interacted with in the editor e.g. enabled/disabled or even configured to handle more complex Archetypes or filters other than the standard ones?

    A way to setup System sequences e.g. what runs first and last or even to run systems at multiple times within the main loop would be very beneficial e.g. Different damage types interleaved with cleaning up dead entities and triggering effects.