Search Unity

Consuming inputs: Have a few game objects handle inputs and make others ignore inputs during 1 frame

Discussion in 'Scripting' started by asperatology, Aug 16, 2015.

  1. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    I would like to know if Unity allows game objects to "consume" inputs (as in, returning early from an event) for the duration of 1 frame (the entire Update() tick).

    Say you have a GUI button on the screen, and the game allows the user to interact other game objects while the GUI button is showing. When the user clicks on the GUI button, it does not interfere with the game (meaning the GUI button has consumed the input event), and the other game objects do not react to the user's GUI button click.

    This is useful to know for RTS games, which is, when the user may need to interact with the GUI elements on the screen, without interfering with the units on the battlefield, otherwise, the units may follow unintended orders the user was doing at the time.
     
  2. Nitugard

    Nitugard

    Joined:
    May 10, 2015
    Posts:
    343
  3. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    I never heard of this class before. It gave me a few questions:
    1. How does one obtain the Event class?
    2. How does one uses the "Event.Use()" function?
    3. Can you trigger it multiple times after resetting the same Event?
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    Well... Event class deals with the legacy Gui stuff as used through the 'OnGUI' message.

    You obtain the current event through 'Event.current'.

    Calling 'Use' on that object sets the event as used, so any other code that occurs in OnGUI in another script accesses Event.current, the event returned will be flagged as used as opposed to flagged as whatever event occurred that tick.

    The event in Event.current is reset every tick of OnGUI in unity.



    Thing is, I don't know if it's what you're looking for. Are you using the legacy GUI system? Or are you just talking about your own GUI (using GameObjects, Colliders, Input class, and maybe even the new UnityGUI system). If that's the case... Event isn't going to help you, and you'll probably have to set up your own flagging system.
     
  5. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    I am using the new Unity UI. I don't use OnGUI(). The input handling (like 1 left click) lasts for the entire duration of all Update()s for all MonoBehaviours and NetworkBehaviours in all of my game objects.

    Would you happen to know where I can find resources on making a "consumable" input system? I don't what the "consumable" behavior in input handling is called. Or is it a component wrapper design where you "wrap" the Input keyDown/Up detections into a custom class and work from there?
     
  6. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    When you're using the new Unity UI and the 'EventSystem' component. This uses layers to deal with things.

    The UI element on top will receive the click event.

    You shouldn't have to deal with a consumable event system when using this as 'EventSystem' takes care of it for you.


    BUT, if you also have in your code some update that checks things like Input.GetMouseButtonDown, here you'll have to deal with it in some manner.

    It's as simple as having boolean values somewhere that any code that accesses some input sets this boolean true if used. Then just reset at the end of every frame.

    Of course it would be best to encapsulate this in some class.

    Of course, if you need it to work in tandem with the 'EventSystem', so that clicks there block clicks elsewhere, or vice versa... well... that's going to get more complicated.

    Really at the end of the day, dealing with all of this comes down to YOUR game and all the things you're doing.
     
  7. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Even RTS games use different implementations of how UI events are handled (consumed)? I didn't know about this, so I guess it's good to know.

    Looking into EventSystem, it said here that I need to use GraphicRaycaster. Do I just use GetComponent<GraphicRaycaster>() to fetch the component in EventSystem, or there's a way to obtain access? I can't tell from the documentation.
     
  8. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    That's just the raycaster used by the EventSystem to check what the mouse clicked in the UI.

    What is going on, what code is running when it shouldn't be? How is that code implemented? What input system are you using for the code that needs to be blocked?

    And yes, of course different RTS's might use different input systems. For one, not all RTS's use unity. I'm not talking about how the UI is layed out... I'm talking about the actual library of code used for input determination. For example there is the legacy OnGUI and the newer Unity GUI system that is built similar to nGUI (yet another option).
     
  9. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    I tried. Don't know what I'm doing.

    GetComponent<GraphicRaycaster>() returns null?

    EDIT: Please give me a sec to respond to your edited post.
     
  10. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Full Input Handling class (Description below):

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. namespace Tutorial {
    7.     public class TutorialInputManager : MonoBehaviour {
    8.         public List<GameObject> selectedObjects;
    9.         public List<GameObject> boxSelectedObjects;
    10.  
    11.         public bool selectionTutorialFlag;
    12.         public bool attackOrderTutorialFlag;
    13.         public bool moveOrderTutorialFlag;
    14.         public bool splitTutorialFlag;
    15.         public bool mergeTutorialFlag;
    16.  
    17.         public bool attackStandingByFlag;
    18.         public GameObject tutorialUnitPrefab;
    19.  
    20.         public TutorialAttackManager attackManager;
    21.         public TutorialSplitManager splitManager;
    22.         public TutorialMergeManager mergeManager;
    23.  
    24.         //----------------------------------
    25.  
    26.         void Start() {
    27.             this.selectedObjects = new List<GameObject>();
    28.             TutorialUnitManager.Instance.allObjects = new List<GameObject>();
    29.             this.boxSelectedObjects = new List<GameObject>();
    30.  
    31.             //this.selectionTutorialFlag = this.attackOrderTutorialFlag = this.moveOrderTutorialFlag = this.splitTutorialFlag = this.mergeTutorialFlag = true;
    32.  
    33.             if (this.attackManager == null) {
    34.                 Debug.LogError("Cannot find attack manager for the tutorial.");
    35.             }
    36.             if (this.splitManager == null) {
    37.                 Debug.LogError("Cannot find split manager for the tutorial.");
    38.             }
    39.  
    40.             GameObject[] existingObjects = GameObject.FindGameObjectsWithTag("Tutorial_Unit");
    41.             foreach (GameObject obj in existingObjects) {
    42.                 TutorialUnitManager.Instance.allObjects.Add(obj);
    43.             }
    44.         }
    45.  
    46.         void Update() {
    47.             SelectOrder();
    48.             MoveOrder();
    49.             AttackOrder();
    50.             SplitOrder();
    51.             MergeOrder();
    52.  
    53.             UpdateStatus();
    54.         }
    55.  
    56.         //----------------------------------
    57.  
    58.         private void UpdateStatus() {
    59.             if (this.selectedObjects.Count > 0 || this.boxSelectedObjects.Count > 0) {
    60.                 if (this.attackStandingByFlag) {
    61.                     foreach (GameObject obj in TutorialUnitManager.Instance.allObjects) {
    62.                         if (this.selectedObjects.Contains(obj)) {
    63.                             TutorialUnit unit = obj.GetComponent<TutorialUnit>();
    64.                             if (!unit.isEnemy) {
    65.                                 unit.SetAttackStandby();
    66.                             }
    67.                         }
    68.                     }
    69.                 }
    70.                 else {
    71.                     foreach (GameObject obj in TutorialUnitManager.Instance.allObjects) {
    72.                         if (obj == null) {
    73.                             TutorialUnitManager.Instance.removeList.Add(obj);
    74.                             continue;
    75.                         }
    76.                         if (this.selectedObjects.Contains(obj) || this.boxSelectedObjects.Contains(obj)) {
    77.                             TutorialUnit unit = obj.GetComponent<TutorialUnit>();
    78.                             if (unit == null) {
    79.                                 TutorialUnitManager.Instance.removeList.Add(obj);
    80.                                 continue;
    81.                             }
    82.                             if (!unit.isEnemy) {
    83.                                 if (unit.isStandingBy) {
    84.                                     unit.SetAttackStandby();
    85.                                 }
    86.                                 if (unit.isAttacking) {
    87.                                     unit.SetAttack();
    88.                                 }
    89.                                 if (unit.isSplitting) {
    90.                                     unit.SetDeselect();
    91.                                     unit.SetAttackCancel();
    92.                                 }
    93.                                 if (unit.isSelected) {
    94.                                     unit.SetSelect();
    95.                                 }
    96.                             }
    97.                         }
    98.                     }
    99.                 }
    100.             }
    101.             else {
    102.                 foreach (GameObject obj in TutorialUnitManager.Instance.allObjects) {
    103.                     if (obj == null) {
    104.                         TutorialUnitManager.Instance.removeList.Add(obj);
    105.                         continue;
    106.                     }
    107.                     TutorialUnit unit = obj.GetComponent<TutorialUnit>();
    108.                     unit.SetDeselect();
    109.                 }
    110.             }
    111.         }
    112.  
    113.         //----------------------------------
    114.  
    115.         private void SelectOrder() {
    116.             if (!this.selectionTutorialFlag) {
    117.                 return;
    118.             }
    119.             if (this.attackStandingByFlag) {
    120.                 return;
    121.             }
    122.             if (Input.GetMouseButtonDown(0)) {
    123.                 if (this.selectedObjects.Count > 0) {
    124.                     foreach (GameObject obj in this.selectedObjects) {
    125.                         TutorialUnit unit = obj.GetComponent<TutorialUnit>();
    126.                         unit.SetDeselect();
    127.                     }
    128.                     this.selectedObjects.Clear();
    129.                 }
    130.                 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    131.                 RaycastHit[] hits = Physics.RaycastAll(ray);
    132.                 bool hasHitUnit = false;
    133.                 foreach (RaycastHit hit in hits) {
    134.                     GameObject obj = hit.collider.gameObject;
    135.                     if (obj.tag.Equals("Tutorial_Unit")) {
    136.                         hasHitUnit = true;
    137.                         if (!this.selectedObjects.Contains(obj)) {
    138.                             TutorialUnit unit = obj.GetComponent<TutorialUnit>();
    139.                             unit.SetSelect();
    140.                             this.selectedObjects.Add(obj);
    141.                         }
    142.                         break;
    143.                     }
    144.                 }
    145.                 if (!hasHitUnit) {
    146.                     this.selectedObjects.Clear();
    147.                 }
    148.             }
    149.             if (Input.GetMouseButton(0)) {
    150.                 foreach (GameObject obj in TutorialUnitManager.Instance.allObjects) {
    151.                     if (obj == null) {
    152.                         TutorialUnitManager.Instance.removeList.Add(obj);
    153.                         continue;
    154.                     }
    155.                     Vector2 screenPoint = Camera.main.WorldToScreenPoint(obj.transform.position);
    156.                     screenPoint.y = Screen.height - screenPoint.y;
    157.                     if (Selection.selectionArea.Contains(screenPoint) && !this.boxSelectedObjects.Contains(obj)) {
    158.                         this.boxSelectedObjects.Add(obj);
    159.                         if (!this.selectedObjects.Contains(obj)) {
    160.                             this.selectedObjects.Add(obj);
    161.                         }
    162.                         TutorialUnit unit = obj.GetComponent<TutorialUnit>();
    163.                         unit.SetSelect();
    164.                     }
    165.                     else if (!Selection.selectionArea.Contains(screenPoint) && this.boxSelectedObjects.Contains(obj)) {
    166.                         this.boxSelectedObjects.Remove(obj);
    167.                         if (this.selectedObjects.Contains(obj)) {
    168.                             this.selectedObjects.Remove(obj);
    169.                         }
    170.                         TutorialUnit unit = obj.GetComponent<TutorialUnit>();
    171.                         unit.SetDeselect();
    172.                     }
    173.                 }
    174.             }
    175.             if (Input.GetMouseButtonUp(0)) {
    176.                 if (this.boxSelectedObjects.Count > 0) {
    177.                     foreach (GameObject obj in this.boxSelectedObjects) {
    178.                         if (!this.selectedObjects.Contains(obj)) {
    179.                             TutorialUnit unit = obj.GetComponent<TutorialUnit>();
    180.                             unit.SetSelect();
    181.                             this.selectedObjects.Add(obj);
    182.                         }
    183.                     }
    184.                     this.boxSelectedObjects.Clear();
    185.                 }
    186.             }
    187.         }
    188.  
    189.         //----------------------------------
    190.  
    191.         private void AttackOrder() {
    192.             if (!this.attackOrderTutorialFlag) {
    193.                 return;
    194.             }
    195.             if (Input.GetKeyDown(KeyCode.A)) {
    196.                 if (!this.attackStandingByFlag) {
    197.                     if (this.selectedObjects.Count > 0) {
    198.                         this.attackStandingByFlag = true;
    199.                         foreach (GameObject obj in this.selectedObjects) {
    200.                             TutorialUnit unit = obj.GetComponent<TutorialUnit>();
    201.                             if (!unit.isEnemy) {
    202.                                 unit.SetAttackStandby();
    203.                             }
    204.                         }
    205.                         //this.selectedObjects.Clear();
    206.                     }
    207.                 }
    208.             }
    209.             if (this.attackStandingByFlag) {
    210.                 if (Input.GetMouseButtonDown(0)) {
    211.                     this.attackStandingByFlag = false;
    212.                     foreach (GameObject obj in this.selectedObjects) {
    213.                         TutorialUnit unit = obj.GetComponent<TutorialUnit>();
    214.                         unit.SetAttackCancel();
    215.                     }
    216.                     this.selectedObjects.Clear();
    217.                 }
    218.                 else if (Input.GetMouseButtonDown(1)) {
    219.                     this.attackStandingByFlag = false;
    220.                     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    221.                     RaycastHit[] hits = Physics.RaycastAll(ray);
    222.                     //bool hasOrderedAttackTarget = false;
    223.                     foreach (RaycastHit hit in hits) {
    224.                         GameObject obj = hit.collider.gameObject;
    225.                         if (obj.name.Equals("Floor")) {
    226.                             foreach (GameObject selected in this.selectedObjects) {
    227.                                 TutorialUnit unit = selected.GetComponent<TutorialUnit>();
    228.                                 if (!unit.isEnemy) {
    229.                                     unit.SetAttackCancel();
    230.                                     unit.SetNewDestination(hit.point);
    231.                                     unit.SetAttack();
    232.                                 }
    233.                             }
    234.                             //hasOrderedAttackTarget = true;
    235.                             break;
    236.                         }
    237.                     }
    238.                     //if (hasOrderedAttackTarget) {
    239.                     //    this.selectedObjects.Clear();
    240.                     //}
    241.                 }
    242.             }
    243.         }
    244.  
    245.         //----------------------------------
    246.  
    247.         private void MoveOrder() {
    248.             if (!this.moveOrderTutorialFlag) {
    249.                 return;
    250.             }
    251.             if (!this.attackStandingByFlag) {
    252.                 if (Input.GetMouseButtonDown(1)) {
    253.                     if (this.selectedObjects.Count > 0) {
    254.                         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    255.                         RaycastHit[] hits = Physics.RaycastAll(ray);
    256.                         foreach (RaycastHit hit in hits) {
    257.                             GameObject obj = hit.collider.gameObject;
    258.                             if (obj.name.Equals("Floor")) {
    259.                                 foreach (GameObject select in this.selectedObjects) {
    260.                                     TutorialUnit unit = select.GetComponent<TutorialUnit>();
    261.                                     if (!unit.isEnemy) {
    262.                                         unit.SetAttackCancel();
    263.                                         unit.SetNoEnemyTarget();
    264.                                         unit.enemies.Clear();
    265.                                         unit.SetStartMoving();
    266.                                         unit.SetNewDestination(hit.point);
    267.                                     }
    268.                                 }
    269.                                 break;
    270.                             }
    271.                         }
    272.                     }
    273.                     //this.selectedObjects.Clear();
    274.                 }
    275.             }
    276.         }
    277.  
    278.         //----------------------------------
    279.  
    280.         private void SplitOrder() {
    281.             if (!this.splitTutorialFlag) {
    282.                 return;
    283.             }
    284.             if (Input.GetKeyDown(KeyCode.S)) {
    285.                 if (this.selectedObjects.Count > 0) {
    286.                     bool enemyCheck = false;
    287.                     foreach (GameObject obj in this.selectedObjects) {
    288.                         TutorialUnit unit = obj.GetComponent<TutorialUnit>();
    289.                         if (unit.isEnemy) {
    290.                             enemyCheck = true;
    291.                         }
    292.                     }
    293.                     if (!enemyCheck) {
    294.                         foreach (GameObject owner in this.selectedObjects) {
    295.                             TutorialUnit unit = owner.GetComponent<TutorialUnit>();
    296.                             GameObject duplicate = GameObject.Instantiate<GameObject>(this.tutorialUnitPrefab);
    297.                             duplicate.transform.position = owner.transform.position;
    298.                             unit.SetDeselect();
    299.                             unit.DisableSelection();
    300.                             unit.SetSplitting();
    301.                             unit = duplicate.GetComponent<TutorialUnit>();
    302.                             unit.SetDeselect();
    303.                             unit.DisableSelection();
    304.                             unit.SetSplitting();
    305.                             unit.initialColor = Color.white;
    306.                             TutorialUnitManager.Instance.allObjects.Add(duplicate);
    307.                             this.splitManager.splitGroups.Add(new SplitGroup(owner, duplicate));
    308.                         }
    309.                     }
    310.                     this.selectedObjects.Clear();
    311.                 }
    312.             }
    313.         }
    314.  
    315.         //----------------------------------
    316.  
    317.         private void MergeOrder() {
    318.             if (!this.mergeTutorialFlag) {
    319.                 return;
    320.             }
    321.             if (Input.GetKeyDown(KeyCode.D)) {
    322.                 if (this.selectedObjects.Count > 0) {
    323.                     bool enemyCheck = false;
    324.                     foreach (GameObject obj in this.selectedObjects) {
    325.                         TutorialUnit unit = obj.GetComponent<TutorialUnit>();
    326.                         if (unit.isEnemy) {
    327.                             enemyCheck = true;
    328.                         }
    329.                     }
    330.                     if (!enemyCheck) {
    331.                         for (int i = 0; i < this.selectedObjects.Count && (i + 1 < this.selectedObjects.Count); i += 2) {
    332.                             TutorialUnit unit = this.selectedObjects[i].GetComponent<TutorialUnit>();
    333.                             unit.SetDeselect();
    334.                             unit.DisableSelection();
    335.                             unit.SetMerging();
    336.                             unit = this.selectedObjects[i + 1].GetComponent<TutorialUnit>();
    337.                             unit.SetDeselect();
    338.                             unit.DisableSelection();
    339.                             unit.SetMerging();
    340.                             this.mergeManager.mergeGroups.Add(new MergeGroup(this.selectedObjects[i], this.selectedObjects[i + 1]));
    341.                         }
    342.                     }
    343.                     this.selectedObjects.Clear();
    344.                 }
    345.             }
    346.         }
    347.     }
    348. }
    349.  
    And this is the dialog handling code for an interactive RTS tutorial.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System;
    4. using System.Collections;
    5. using System.Collections.Generic;
    6.  
    7. namespace Tutorial {
    8.     [Serializable]
    9.     public struct DialogArrow {
    10.         public Vector2 position;
    11.         public float angle;
    12.  
    13.         public DialogArrow(float x, float y, float angle) {
    14.             this.position = new Vector2(x, y);
    15.             this.angle = angle;
    16.         }
    17.     }
    18.  
    19.     [Serializable]
    20.     public struct DialogText {
    21.         public Vector2 position;
    22.         public string message;
    23.  
    24.         public DialogText(float x, float y, string message) {
    25.             this.position = new Vector2(x, y);
    26.             this.message = message;
    27.         }
    28.     }
    29.  
    30.  
    31.     [Serializable]
    32.     public struct DialogProperty {
    33.         public DialogText dialogText;
    34.         public DialogArrow dialogArrow;
    35.         public bool changePosition;
    36.         public bool showArrow;
    37.         public float elapsedTime;
    38.  
    39.         public DialogProperty(DialogText text, DialogArrow arrow, bool shouldChangePositionOnNextDialog, bool showArrowOnNextDialog, float time) {
    40.             this.dialogText = text;
    41.             this.dialogArrow = arrow;
    42.             this.changePosition = shouldChangePositionOnNextDialog;
    43.             this.showArrow = showArrowOnNextDialog;
    44.             this.elapsedTime = time;
    45.         }
    46.     }
    47.  
    48.     public class TutorialDialog : MonoBehaviour {
    49.         public RectTransform dialogTransform;
    50.         public RectTransform arrowTransform;
    51.         public GameObject mainDialog;
    52.         public GameObject arrow;
    53.         public List<DialogProperty> properties;
    54.         public int propertyIterator;
    55.         public bool runCoroutine;
    56.  
    57.         void Start() {
    58.             if (this.mainDialog == null) {
    59.                 Debug.LogError("Dialog: Something is wrong.");
    60.             }
    61.             if (this.arrow == null) {
    62.                 Debug.LogError("Arrow: Something is wrong.");
    63.             }
    64.             this.dialogTransform = this.mainDialog.GetComponent<RectTransform>();
    65.             this.arrowTransform = this.arrow.GetComponent<RectTransform>();
    66.             this.properties = new List<DialogProperty>();
    67.             this.runCoroutine = false;
    68.             Initialize();
    69.         }
    70.  
    71.         void OnGUI() {
    72.             if (this.propertyIterator < this.properties.Count) {
    73.                 DialogProperty property = this.properties[this.propertyIterator];
    74.                 Text text = this.mainDialog.GetComponentInChildren<Text>();
    75.                 if (text != null) {
    76.                     text.text = property.dialogText.message;
    77.                 }
    78.                 if (property.changePosition) {
    79.                     if (this.dialogTransform != null) {
    80.                         this.dialogTransform.anchoredPosition = property.dialogText.position;
    81.                     }
    82.                 }
    83.                 if (property.showArrow) {
    84.                     this.arrowTransform.anchoredPosition = property.dialogArrow.position;
    85.                     this.arrowTransform.localRotation = Quaternion.Euler(0f, 0f, property.dialogArrow.angle);
    86.                 }
    87.                 else {
    88.                     this.arrowTransform.anchoredPosition = new Vector2(0f, 260f);
    89.                 }
    90.             }
    91.         }
    92.  
    93.         void Update() {
    94.             if (this.runCoroutine) {
    95.                 this.StartCoroutine(CR_DialogSwitch());
    96.             }
    97.         }
    98.  
    99.         private IEnumerator CR_DialogSwitch() {
    100.             DialogProperty property = this.properties[this.propertyIterator];
    101.             if (property.elapsedTime > 0f) {
    102.                 if (this.mainDialog.activeSelf) {
    103.                     this.mainDialog.SetActive(false);
    104.                 }
    105.                 if (this.arrow.activeSelf) {
    106.                     this.arrow.SetActive(false);
    107.                 }
    108.                 this.properties[this.propertyIterator] = property;
    109.                 yield return new WaitForSeconds(property.elapsedTime);
    110.             }
    111.             if (!this.mainDialog.activeSelf) {
    112.                 this.mainDialog.SetActive(true);
    113.             }
    114.             if (!this.arrow.activeSelf) {
    115.                 this.arrow.SetActive(true);
    116.             }
    117.             this.runCoroutine = false;
    118.         }
    119.  
    120.         public void OnTutorialButtonClick() {
    121.             this.propertyIterator++;
    122.             if (this.propertyIterator < this.properties.Count) {
    123.                 this.runCoroutine = true;
    124.             }
    125.             switch (this.propertyIterator) {
    126.                 default:
    127.                     break;
    128.                 case 6:
    129.                 case 9:
    130.                 case 11:
    131.                 case 15:
    132.                     TutorialManager.Instance.IncrementState();
    133.                     break;
    134.             }
    135.         }
    136.  
    137.      
    138.     }
    139. }
    140.  
    141.  
    Typing this in Xenforo forum text editor is slow as hell. Spell check for the win.

    As you can see, in the Input Manager, I poll the Inputs to check and see if the user has pressed keys or mouse buttons in the Update() function. In the Dialog class, I only activate the OnTutorialButtonClick() when the user presses a button. Since InputManager polls for hardware key changes, while the EventSystem checks for UI updates, I would to find a way to have EventSystem block polling after it detects an UI update.

    That is where GraphicsRaycaster comes in. I might be able to obtain the mouse button click event, and check to see if it's the UI or the input polling, and turn off the input polling first before UI updates happen.

    Just trying to use GameObject.Find("EventSystem").GetComponent<GraphicsRaycaster>() doesn't give much, since it returns null.

    Oh yeah, I only use OnGUI() for the fact that it updates every other frames (not Update() or FixedUpdate(), and that it runs only when the user does something (key press, move cursor, etc.), which is what I wanted). It has nothing to do with Legacy UI.
     
  11. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,532
    Sorry dude, it's late here, tomorrow I can come back and take a look at what you got and give you some pointers.

    Otherwise I bet the likes of @eisenpony or @BoredMormon will come along and give you a helping hand.
     
  12. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I guess that means me. The problem is not so much consuming input events. It's that Unity has at least three different types of input events.
    • OnGUI events
    • OnMouseDown method calls
    • EventSystem interface calls through the raycasters
    If you move all of your input logic onto one system, preferably the EventSystem, then Unity will take care of blocking pretty logically.

    Anyway, enough theory. Check out this video I did thy explains how to do this.

     
  13. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Wow, that's simple. Your video is really wonderful and direct. I liked it. If I have more questions, I will post later.

    @lordofduct This is solved by the video, so you don't have to look at my code posted above.
     
    Kiwasi likes this.
  14. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Thanks. I'm trying to make or find them for a lot of common questions that come up. Sometimes linking in a video is easier then explaining in writing.