I'm getting error an error on this piece of code:

if (EventSystem.current.IsPointerOverGameObject())

The error: NullReferenceExpection: object reference not set to an instance of an object playercontroller.update() { at assets/script/palyer/playercontroller.cs:21)

Any solution to this?

  • \$\begingroup\$ Maybe the EventSystem object was removed from the canvas. Right click -> UI -> EventSystem to add it back \$\endgroup\$ Aug 14, 2020 at 16:39

1 Answer 1


The error message is there to tell you what the problem is. A NullReferenceException means you tried to access a variable that is currently null:

Object a = null;
a.ToString();  <-- this line throws a NullReferenceException!

So in your case, assuming EventSystem is a class, EventSystem.current is null.

As this is Unity, the most likely issue is that you haven't added an EventSystem to your current scene, so there is no current EventSystem.


Not the answer you're looking for? Browse other questions tagged .