UI Button OnClick Function - How to get name of button that was clicked?

How can I get the button name that is being clicked, without having to pass a parameter to the function?

[UPDATED]

I’m using Unity 5.4.0b24 (64-bit)

UnityEngine.EventSystems;
public class EventManager
{
  public void OnButtonClick()
  {
      var go = EventSystem.current.currentSelectedGameObject;
       if (go != null)
          Debug.Log("Clicked on : " + go.name);
        else
          Debug.Log("currentSelectedGameObject is null");
   }
}

See screenshot of the button inspector setup:

EventSystem.current.currentSelectedGameObject = null on debug this function.

Result:

currentSelectedGameObject is null
UnityEngine.Debug:Log(Object)
EventManager:OnButtonClick() (at Assets/Scripts/EventManager.cs:19)
UnityEngine.EventSystems.EventSystem:Update()

Is there any property that can be accessed? Since gameObject.name returns the name of GameObject on Script class as attached (Test.cs).

How can I get the information without using Event Trigger? Its possible?

Thanks in advance!

And I found the problem in my case:

74144-solved-stru.png

I only changed the Navigation option of Button component ‘None’ to ‘Automatic’ (or any other), and all went to work!

Thanks for all the answers!

Yo, maybe you will have to test nullity of variables before using them (:

	void Update ()
	{
		var currentEventSystem = EventSystem.current;
		if(currentEventSystem == null) { return; }

		var currentSelectedGameObject = currentEventSystem.currentSelectedGameObject;
		if(currentSelectedGameObject == null) { return; }

		Debug.Log(currentSelectedGameObject.name);
	}

I just created this simple script:

using UnityEngine;
using UnityEngine.EventSystems;

public class UI_Event_Receiver : MonoBehaviour
{ 
    public void OnButtonClick()
    {
        var go = EventSystem.current.currentSelectedGameObject;
        if (go != null)
            Debug.Log("Clicked on : "+ go.name);
        else
            Debug.Log("currentSelectedGameObject is null");
    }
}

I attached it to the MainCamera (any other object would work as well). I created two buttons and set the OnClick event of both buttons to that method:

And this is the result:

74093-onclickevent2.png

The way you present your question is confusing as others have already said. You have two different classes and the one class that you actually use (your EventManager) doesn’t even use “currentSelectedGameObject”. In my example i never get the message “currentSelectedGameObject is null”.