Search Unity

DefaultWorldInitialization messes up PlayerLoop

Discussion in 'Entity Component System' started by OndrejP, Jul 7, 2019.

  1. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    304
    I use PlayerLoop to setup custom callbacks for my Game.

    When I start using entities and don't disable Default World Initialization, it just discards any of my hook and replaces player loop with it's own (default loop + it's stuff). Below is method which does that, it's part of Entities package:

    Code (CSharp):
    1.  
    2. // ScriptBehaviourUpdateOrder.UpdatePlayerLoop
    3. public static void UpdatePlayerLoop(World world)
    4. {
    5.     var playerLoop = PlayerLoop.GetDefaultPlayerLoop();
    6.     if (world != null)
    7.     {
    8.         // Modify player loop
    9.     }
    10.     PlayerLoop.SetPlayerLoop(playerLoop);
    11.     currentPlayerLoop = playerLoop;
    12. }
    13.  
    14. // PlayerLoop API:
    15. public static PlayerLoopSystem GetDefaultPlayerLoop();
    16. public static void SetPlayerLoop(PlayerLoopSystem loop);
    17.  
    I consider whole PlayerLoop API unfortunate, because there's no way to get current player loop.
    This prevents more that one independent system to work with PlayerLoop.
    If there's another package (independent of Entities), which wants to use PlayerLoop, there's simply no way of doing it, either Entities would rewrite player loop or the other package would rewrite the player loop.

    There is dirty workaround for my case (at least):
    1) Wait until DefaultWorldInitialization modifieds PlayerLoop
    2) Modify ScriptBehaviourUpdateOrder.CurrentPlayerLoop (this is available only AFTER 1))
    3) Call PlayerLoop.SetPlayerLoop

    Am I missing something? This seems to me like big oversight...
     
    Jazok likes this.