Search Unity

Disabling AutomaticWorldBootstrap but keeping hybrid injection hooks

Discussion in 'Entity Component System' started by sahildhanju, May 3, 2018.

  1. sahildhanju

    sahildhanju

    Joined:
    Mar 27, 2018
    Posts:
    6
    Hi, I would like to completely disable using AutomaticWorldBootstrap and avoid using DefaultWorldInitialization. I have tried what other forum posts have said in defining UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP to stop AutomaticWorldBootstrap.

    The issue is that the Initialize function in DefaultWorldInitialization sets up the hybrid injection hooks.

    InjectionHookSupport.RegisterHook(new GameObjectArrayInjectionHook());
    InjectionHookSupport.RegisterHook(new TransformAccessArrayInjectionHook());
    InjectionHookSupport.RegisterHook(new ComponentArrayInjectionHook());

    And I can't access these outside of the Unity.Entities namespace. How else would I be able to set up proper hybrid InjectionHookSupport without using the DefaultWorldInitialization?
     
    S_Darkwell likes this.
  2. jamiebrynes

    jamiebrynes

    Joined:
    Sep 12, 2017
    Posts:
    18
  3. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    Haven't tried this myself. But I would think about either re-implement these 3 subclasses since InjectionHook is public. Or for a quick test, just change the entities package source code directly and make those 3 classes public.
     
    deus0 likes this.
  4. Vengarioth

    Vengarioth

    Joined:
    Feb 11, 2014
    Posts:
    1
    What might work for now is rather than disabling the default bootstrapper just destroy the world right after the bootstrapper ran and run your own initialization. It might be enough until a better way comes.

    Code (CSharp):
    1.  
    2. World.DisposeAllWorlds();
    3. ScriptBehaviourUpdateOrder.UpdatePlayerLoop();
    4. // run your initialization here
    5.  
     
  5. sahildhanju

    sahildhanju

    Joined:
    Mar 27, 2018
    Posts:
    6
    Issue with that is I have code that relies on other state in the `OnCreateManager` for some systems and they won't be initialized when the default bootstrap is first ran. I figured it out though using reflection in case you want to try.


    public static void SetupInjectionHooks()
    {
    // Reflection to get internal hook classes. Doesn't seem to be a proper way to do this.
    var gameObjectArrayInjectionHookType =
    typeof(Unity.Entities.GameObjectEntity).Assembly.GetType("Unity.Entities.GameObjectArrayInjectionHook");
    var transformAccessArrayInjectionHookType =
    typeof(Unity.Entities.GameObjectEntity).Assembly.GetType(
    "Unity.Entities.TransformAccessArrayInjectionHook");
    var componentArrayInjectionHookType =
    typeof(Unity.Entities.GameObjectEntity).Assembly.GetType("Unity.Entities.ComponentArrayInjectionHook");
    InjectionHookSupport.RegisterHook(
    (InjectionHook) Activator.CreateInstance(gameObjectArrayInjectionHookType));
    InjectionHookSupport.RegisterHook(
    (InjectionHook) Activator.CreateInstance(transformAccessArrayInjectionHookType));
    InjectionHookSupport.RegisterHook(
    (InjectionHook) Activator.CreateInstance(componentArrayInjectionHookType));
    }



    // Taken from DefaultWorldInitalization.cs
    SetupInjectionHooks(); // Register hybrid injection hooks
    PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000); // Clean up worlds and player loop

     
  6. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    Hi @sahildhanju, do u mean after define
    UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP
    , u cannot use
    [Inject] Group group
    anymore at ComponentSystem?
     
  7. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    Just the hybrid ones: ie. GameObject, Monobehaviour Components, etc...