Search code examples
debuggingmonodevelopunity-game-engine

Selecting a GameObject in Unity Editor from MonoDevelop Debugger


I'm debugging a MonoBehaviour script in MonoDevelop.

There is a way to select (in the Unity Editor) the gameobject the current paused script is attached to?

(I have multiple instances of the same prefab with that script attached, so finding it in the Hierarchy is not trivial)


Solution

  • You can do this fairly easily by taking advantage of Unity's Selection class. Just be sure to add using UnityEditor; at the top of your script.

    To select the gameObject you are debugging in your hierarchy, simply set the Selection.activeGameObject property in your script right after the line you are placing your break point on. For example:

    void Update()
    {
        int breakPoint = 5; //your breakpoint is placed here
    
        //select this gameObject in the hierarchy 
        Selection.activeGameObject = this.gameObject; 
    }