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 to make it work? !EventSystem.current.IsPointerOverGameObject()

Discussion in 'Editor & General Support' started by LokenGarviel, Aug 26, 2020.

?

How to fix it?!EventSystem.current.IsPointerOverGameObject()

  1. no longer works on this version

    3 vote(s)
    100.0%
  2. error in parameter

    0 vote(s)
    0.0%
Multiple votes are allowed.
  1. LokenGarviel

    LokenGarviel

    Joined:
    Aug 25, 2020
    Posts:
    12
    I started with the book "unity in action" and got to the point of clicking on the gui with
    ````
    using UnityEngine.EventSystems;
    .....
    void Update() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
    .......
    }
    Without !EventSystem.current.IsPointerOverGameObject() everything works, but after an error comes out
    ```
    NullReferenceException: Object reference not set to an instance of an object
    RayShooter.Update () (at Assets/scripts/RayShooter.cs:27)
    ```
    Maybe someone studied this book and found a solution to the problem? Veria unity 2019.4.
    Thanks.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    Did you add an EventSystem to your scene?
     
  3. LokenGarviel

    LokenGarviel

    Joined:
    Aug 25, 2020
    Posts:
    12
    Yes, i have ' UnityEngine.EventSystems; '
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    No im not asking about a using statement in your code. There's an actual EventSystem component that needs to be attached to a GameObject in your scene. You can create it from the menu similar to how you would create a cube etc.