Get Field Selection

I’m working on an EditorWindow and I need the selected object in the window (the inspector) NOT the scene view, so no Selection.activeObject, or anything like that. How can I get that object? I know there’s GUIUtility.GetControlID(), but I have no idea which field is which and I would prefer to just get the object.

Thanks.

Selection.activeObject does get the object that is showing in the inspector.

Dude… please, I explicitly said no comments about Selection.activeObject. I don’t need the selected scene object. I need the selected field that is in the selected object in the scene view. Field, as in variable, belonging to the selected object.

Then maybe you shouldn’t refer to it as an Object, but instead a Field.

Sorry, I just phrased it as an object, because I needed the object, not a number that represents the object, or something and I believe I actually wrote “field” in there somewhere. But it doesn’t matter because I found the solution.

No wait, actually it’s not solved, tried using Object.GetHashCode with GUIUtility,GetControlID(), but didn’t work, unfortunately.

Okay I figured out I need to use GUIUtility.keyboardControl, but now I just need a way to get the control id for an object with the object.

Are you saying you want the Object from the currently selected EditorGUI.ObjectField?

Yes, but doesn’t matter actually figured it out for real this time. I use GUI.SetNextControlName().