Search Unity

UT Fences

Discussion in 'Project Tiny' started by SoerenBachNielsen, Dec 14, 2018.

  1. SoerenBachNielsen

    SoerenBachNielsen

    Joined:
    Dec 27, 2012
    Posts:
    38
    Hey!

    I'm trying to make an InputSystem which naturally should run before everything else of my user code. I'm trying to use fences, but it doesn't seem to work. Am I using it wrong, or is it a bug?

    This is my very simple input system:
    Code (CSharp):
    1. namespace game {
    2.  
    3.     export class PlayerInputSystemFilter extends ut.EntityFilter {
    4.         tag: game.PlayerTag;
    5.         input: game.PlayerInput;
    6.     }
    7.  
    8.     @ut.executeAfter(ut.Shared.InputFence)
    9.     @ut.executeBefore(ut.Shared.UserCodeStart)
    10.     export class PlayerInputSystem extends ut.ComponentSystem {
    11.  
    12.         filter: PlayerInputSystemFilter = new PlayerInputSystemFilter();
    13.         logged: boolean = false;
    14.  
    15.         OnUpdate(): void {
    16.             if (!this.logged) {
    17.                 console.log("reading input");
    18.                 this.logged = true;
    19.             }
    20.             this.filter.ForEach(this.world, (e) => {
    21.                 this.filter.input.MouseButtonDown = false;
    22.                 this.filter.input.MouseButtonUp = false;
    23.  
    24.                 if (ut.Runtime.Input.getMouseButtonDown(0)) {
    25.                     this.filter.input.MouseButtonDown = true;
    26.                 }
    27.                 else if (ut.Runtime.Input.getMouseButtonUp(0)) {
    28.                     this.filter.input.MouseButtonUp = true;
    29.                 }
    30.             });
    31.         }
    32.     }
    33. }
    And here is another system which should execute after the input system, but the log says otherwise:

    Code (CSharp):
    1. namespace game {
    2.  
    3.     /** New System */
    4.     export class PlayerScalePenaltySystem extends ut.ComponentSystem {
    5.         logged: boolean = false;
    6.  
    7.         OnUpdate(): void {
    8.             if (!this.logged) {
    9.                 console.log("scaling");
    10.                 this.logged = true;
    11.             }
    12.         }
    13.     }
    14. }
    Log:
     
  2. etienne_unity

    etienne_unity

    Unity Technologies

    Joined:
    Aug 31, 2017
    Posts:
    54
    Hi @SoerenBachNielsen

    I believe you have to explicitly schedule
    PlayerScalePenaltySystem
    between
    ut.Shared.UserCodeStar
    t and
    ut.Shared.UserCodeEnd
    - which feels a lot like a bug on our side (systems with no constraints should use these by default).
     
    facundo_unity961 likes this.
  3. SoerenBachNielsen

    SoerenBachNielsen

    Joined:
    Dec 27, 2012
    Posts:
    38
    Great, thanks for the reply @etienne_unity . I'll try that method on Monday.

    But yes, I would recommend the other approach. I feel like it could become very tedious to add fences on every new system we create, instead of just being able to tell a specific system to run before everything else :)
     
  4. SoerenBachNielsen

    SoerenBachNielsen

    Joined:
    Dec 27, 2012
    Posts:
    38
    Alright, explicitly stating that my scaling system should be executed in between user code and making my input system execute before user code did the trick.
    But as you mentioned, would much rather all the systems which had no custom fences, should always be run in the user code.