hi,how to reference Eventsystem? Gameobject.find ("EventSystem"); returns error as well as GameObject.Find ("EventSystem").GetComponent();

i got it set to private, not sure how to pull this off. thanks :slight_smile:

Make sure you are referencing the EventSystems namespace:

using UnityEngine.EventSystems;

If that’s there, then you have to get the component:

private EventSystem eventSystem;

// Use this for initialization
void Start ()
	this.eventSystem = GameObject.Find ("EventSystem").GetComponent<EventSystem> ();

You are trying to convert a GameObject to an EventSystem. What you should do is get the EventSystem component of the GameObject.

How to get the EventSystem component?

eventsys = GameObject.Find ("EventSystem").GetComponent();

Mark this answer as helpful if it helped you.

bobisgod234 :
Do you have an event system in your scene, and is it attached to a GameObject called “EventSystem”?

You can use


to access the current EventSystem in use, instead of GameObject.Find. This also makes it work regardless of what you name the GameObject, so its a better choice than using GameObject.Find anyway.

Verify the code is being executed by putting a Debug.Log() statement where you try to get the EventSystem, and check the console.