Accessing a buttons rect from GUILayout

Hello,

Is it possible to access the rect of a button from a GUILayout?

For example:

GUILayout.BeginVertical();
     GUILayout.Button("This is a button.");
GUILayout.EndVertical();

Would it be possible to access that button’s rect? I need the rect because in my game I am using a tooltip that only shows when the mouse is hovering over specific buttons.

I couldn’t find anything on Unity’s documentation regarding this Unity - Scripting API: GUILayout but I’m assuming it’s possible – seems like quite an obvious function to implement.

Thanks in advance!

EDIT

I got it! All I had to do was check if the tooltip != “”;

I tried tooltip != null and that didn’t work, but comparing it to an empty string, “”, does.

I hope this helps someone in the future, and thank you again MarkPixel! When I am finished with this game, I’ll definitely have to include a few members of the Unity community in my credits as a “Special Thanks To”

:slight_smile:

Don’t know what your work-around was, but the function you are looking for is

GUILayoutUtility.GetLastRect()