Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ICustomBootstrap Feedback

Discussion in 'Entity Component System' started by tertle, Mar 4, 2019.

  1. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
    Workable enough of a solution to replace my custom initialization which is nice, one less thing to maintain, but it'd be great if you could pass in if it is an editor world.

    Otherwise you need to duplicate the checks, for example having to do something like this

    Code (CSharp):
    1.  
    2.        public List<Type> Initialize(List<Type> systems)
    3.        {
    4. #if UNITY_EDITOR
    5.             var isEditorWorld = !EditorApplication.isPlaying;
    6. #else
    7.             var isEditorWorld = false;
    8. #endif
    9.  
    10.             foreach (var type in systems)
    11.             {
    12.                 if (isEditorWorld)
    13.                 {
    14.                     if (!Attribute.IsDefined(type, typeof(ExecuteAlways)))
    15.                     {
    16.                         continue;
    17.                     }
    18.                 }
     
    Last edited: Mar 4, 2019
    JesOb and Singtaa like this.
  2. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    Also wanted to post some feedback on this. With the ScriptBehaviourUpdateOrder overhaul and ICustomBootstrap, I can finally get rid of all the extra reflection code in my custom bootstrap. Now it's tiny (loading 2 worlds with Systems in different assemblies):

    Code (CSharp):
    1. public class EcsBootstrap : MonoBehaviour, ICustomBootstrap {
    2.  
    3.     public World ServerWorld => serverWorld;
    4.     public World ClientWorld => clientWorld;
    5.  
    6.     World serverWorld;
    7.     World clientWorld;
    8.  
    9.     void Awake() {
    10.         DefaultWorldInitialization.Initialize("Client World", false);
    11.         clientWorld = World.Active;
    12.         DefaultWorldInitialization.Initialize("Server World", false);
    13.         serverWorld = World.Active;
    14.     }
    15.  
    16.     public List<Type> Initialize(List<Type> systems) {
    17.       var otherAsmName = World.Active.Name == "Server World" ? "ServerAsm" : "ClientAsm";
    18.       return systems.Where((t) => t.Assembly.GetName().Name != otherAsmName).ToList();
    19.     }
    20.  
    21. }
    I have two nitpicks though:

    1) ICustomBootstrap.Initialize should also have the World passed in.
    2) DefaultWorldInitialization.Initialize should return the World that is just created.

    Having to check World.Active doesn't feel righteous to me.

    Update:

    Actually 0.0.26 has some issues with setting up multiple worlds. See here: https://forum.unity.com/threads/scr...ger-support-multiple-worlds-in-0-0-26.640279/
     
    Last edited: Mar 7, 2019
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
    I'm not a fan of using a static and while the world is always set to World.Active right before it's called, can we guarantee this behavior in the future?

    All my systems are modular and each have their own custom little installer so I just used a quick interface

    Code (CSharp):
    1.     public interface IInstaller
    2.     {
    3.         void Initialize(World world, List<Type> systems);
    4.     }
    and the actual ICustomBootstrap just passes the World.Active to it.
     
    Last edited: Mar 5, 2019
  4. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    Yes, exactly. And in a multi-world setup, World.Active is quite irrelevant. APIs in general should avoid depending on World.Active.
     
    JesOb, julian-moschuering and M_R like this.