I have a table UI that uses a Button class for drawing cells. The Button object is eventually drawn using a GUI.Button call like follows:
GUI.Button(Boundary, Content, Style);
This works if I use the button independently of my table code and I know the code that makes this call is being reached because the button is correctly displayed in my table.
The problem is GUI.Button(…) is always returning false on click. To complicate things I have code that handles row selection which responds to clicks as well. So I’m wondering what sort of issues should I look for to find out why GUI.Button(…) would always return false. If, for example, row selection were receiving a clicked event as well would the event be consumed and not passed on to the individual cell/Button that was pressed?
Thanks,
Ben
First off, welcome to the forums! 
Can you show us some code that you’re using where clicking the button never triggers a positive result? I don’t have any general ideas as to why this might be happening and looking at some code may help us sort this out with you.
I can’t post all the code because its spans a bunch of classes but basically we have a UI library that maintains the state of complex UI widgets like a Table. The table ultimately delegates the cell drawing to this method on our Button class:
protected override void DrawDelegate() {
Boolean buttonPressed = GUI.Button(Boundary, Content, Style);
//Debug.Log("buttonPressed: " + buttonPressed);
if (buttonPressed) {
Debug.Log("Checking action listeners");
if (buttonActionListeners != null) {
ButtonAction ba = new ButtonAction();
ba.Type = ButtonAction.TYPE.UpDown;
ba.Source = this;
Debug.Log("Notifying listeners of button");
buttonActionListeners.NotifyListeners(ba);
}
}
}
This method is called and the Button appears as a cell in the Table as it should but clicking it never produces a true result and so the if statement is never satisfied. This same code is used for standalone buttons that aren’t part of a table and works fine. My primary question is, is it possible that the event is being consumed as a click on one of the UI elements that make up the table, perhaps its container or something like that? Just to be sure, I disabled row selection and had the same problem.
For now I have this hack around the problem:
private Boolean buttonPressHack(){
if(this.State.Boundary.Contains(Event.current.mousePosition)) {
if(Event.current.clickCount > 0){
return true;
}
}
return false;
}
And have modified the if statement from the DrawDelegate like so:
if (buttonPressed || buttonPressHack()) { ... }
I am having a very similar problem to this. In my instance, I am making a right-click menu for onscreen objects. The idea is that the button clicks should perform the actions assigned to them, and immediately afterwards I check for a click and close the menu if one occurred.
Without this check, everything runs fine as you would expect. As soon as you put it in, the button will never return true.
I have tried deferring the hiding of the menu until the next frame renaming the onVisible() method (seeing as it’s highlighted in the editor I thought it might conflict). Those were the only wierd things I could see in the code, and they didn’t help 
using UnityEngine;
using System.Collections;
public class RightClickMenu : MonoBehaviour {
public Texture backgroundTexture;
private ArrayList behaviours = new ArrayList();
private Vector3 menuPos = new Vector3();
public int MENU_WIDTH = 170;
public int ITEM_HEIGHT = 28;
public bool visible = false;
//================================================================================================================
public bool isVisible {
get {
return visible;
} set {
visible = value;
}
}
//================================================================================================================
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
if (isVisible) {
return;
}
// Make a background box
GUI.Box(new Rect(menuPos.x, menuPos.y, MENU_WIDTH + ITEM_HEIGHT / 2, behaviours.Count * ITEM_HEIGHT + ITEM_HEIGHT / 2), new GUIContent(backgroundTexture));
int i = 0;
foreach (GameBehaviour b in behaviours) {
bool executeBehaviour = GUI.Button(
new Rect(menuPos.x + ITEM_HEIGHT / 4, menuPos.y + i * ITEM_HEIGHT + ITEM_HEIGHT / 4, MENU_WIDTH, ITEM_HEIGHT),
b.actionText
);
if (executeBehaviour) {
Debug.Log("Executing right click menu behaviour: " + b.actionText);
b.Execute();
}
++i;
}
// if we have clicked anything at all, the menu closes
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) {
isVisible = false; // if this is commented out, b.Execute() above will be called
}
}
//================================================================================================================
public void AddAction(GameBehaviour b) {
// add to behaviours
behaviours.Add(b);
isVisible = true;
}
public void ClearActions() {
behaviours.Clear();
isVisible = false;
}
//================================================================================================================
// positions the menu onscreen
public void Position() {
menuPos = Input.mousePosition;
float screenHalf = Camera.main.pixelHeight / 2;
menuPos.y = (screenHalf - menuPos.y) + screenHalf;
}
}
Sounds like your events might be consumed by some control. Top help debug this (and find out where the event gets consumed), you can check Event.current.type == EventType.Used in your code.