Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How do you create multiple worlds?

Discussion in 'Entity Component System' started by wusticality, Jun 4, 2018.

  1. wusticality

    wusticality

    Joined:
    Dec 15, 2016
    Posts:
    71
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    anatsanzh likes this.
  3. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,554
    Note that by mimicking DefaultWorldInstantiation you would not be able to do :
    1. // Register hybrid injection hooks
    2. InjectionHookSupport.RegisterHook(new GameObjectArrayInjectionHook());
    3. InjectionHookSupport.RegisterHook(new TransformAccessArrayInjectionHook());
    4. InjectionHookSupport.RegisterHook(new ComponentArrayInjectionHook());
    As all of those 3 custom hooks are private class. If you still have a default world instantiation then fine, but if you also disable that too you lose an ability to inject components, inject game objects, and inject transform access.
     
    Enzi likes this.
  4. wusticality

    wusticality

    Joined:
    Dec 15, 2016
    Posts:
    71
    In the long term I hope they have a way to create multiple worlds programmatically, making things magic is always very frustrating and limiting.
     
    palex-nx and starikcetin like this.
  5. wusticality

    wusticality

    Joined:
    Dec 15, 2016
    Posts:
    71
    Thanks for this, I'll take a look.
     
  6. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    335
    Wish I could upvote this a hundred times.
     
    T-Zee likes this.
  7. mgmhunt

    mgmhunt

    Joined:
    Apr 1, 2013
    Posts:
    60
    Had similar issue and can solve via reflection

    https://forum.unity.com/threads/solved-cant-inject-componentarray-injectcomponentgroup-cs.551575/

    Code (CSharp):
    1. Assembly unityEntitiesAssembly = Assembly.Load("Unity.Entities.Hybrid, Version=0.0.0.0");
    2. Type hookType;
    3. hookType = unityEntitiesAssembly.GetType("Unity.Entities.GameObjectArrayInjectionHook");
    4. InjectionHookSupport.RegisterHook(Activator.CreateInstance(hookType) as InjectionHook);
    5. hookType = unityEntitiesAssembly.GetType("Unity.Entities.TransformAccessArrayInjectionHook");
    6. InjectionHookSupport.RegisterHook(Activator.CreateInstance(hookType) as InjectionHook);
    7. hookType = unityEntitiesAssembly.GetType("Unity.Entities.ComponentArrayInjectionHook");
    8. InjectionHookSupport.RegisterHook(Activator.CreateInstance(hookType) as InjectionHook);
     
    Last edited: Nov 18, 2018
  8. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    908
    Do you know where these are used? Specifically the ComponentArrayInjection. I'm using a custom world but never added these lines and I have no obvious missing "features". [Inject] is working fine so what is this for?
     
  9. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    If you use your world with default world it works fine.
     
  10. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    908
    What classifies as default world? Using the default bootstrapper?
    I'm using [DisableAutoCreation] in all the systems, pretty much like:
    https://github.com/Unity-Technologies/FPSSample/blob/master/Assets/Scripts/Game/Entity/GameWorld.cs
    They use a new World() and the Injection part later. Is the injectionhook set in the world constructor now?
    What's weirding me out is that I have the InjectionHook commented out and ComponentArrays in systems still work. So what does it do?

    Also, FPSSample uses TransformAccessArray but has the injection commented out.
     
  11. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    Default world is default world created by ECS for editor/play modes, it creates always, untill you not disable it by declaring UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP
     
    Dr_SuiuS and Enzi like this.