Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Get Field Selection

Discussion in 'Scripting' started by llamagod, Jan 20, 2016.

  1. llamagod

    llamagod

    Joined:
    Sep 27, 2015
    Posts:
    76
    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.
     
  2. The-Little-Guy

    The-Little-Guy

    Joined:
    Aug 1, 2012
    Posts:
    297
    Selection.activeObject does get the object that is showing in the inspector.
     
  3. llamagod

    llamagod

    Joined:
    Sep 27, 2015
    Posts:
    76
    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.
     
  4. The-Little-Guy

    The-Little-Guy

    Joined:
    Aug 1, 2012
    Posts:
    297
    Then maybe you shouldn't refer to it as an Object, but instead a Field.
     
  5. llamagod

    llamagod

    Joined:
    Sep 27, 2015
    Posts:
    76
    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.
     
  6. llamagod

    llamagod

    Joined:
    Sep 27, 2015
    Posts:
    76
    No wait, actually it's not solved, tried using Object.GetHashCode with GUIUtility,GetControlID(), but didn't work, unfortunately.
     
  7. llamagod

    llamagod

    Joined:
    Sep 27, 2015
    Posts:
    76
    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.
     
  8. roojerry

    roojerry

    Joined:
    Mar 18, 2013
    Posts:
    68
    Are you saying you want the Object from the currently selected EditorGUI.ObjectField?
     
  9. llamagod

    llamagod

    Joined:
    Sep 27, 2015
    Posts:
    76
    Yes, but doesn't matter actually figured it out for real this time. I use GUI.SetNextControlName().