- Home /
Editor Script - How to process a mouseclick in the scene?
My Editor script (C#) needs to know which object the user clicked on in the scene, but how can I do this without the Editor's parent-object becoming deselected in the Hierarchy?
e.g. I have an empty game object "manager" with my script & editor script attached; when "manager" is selected in the hierarchy I can see my custom editor GUI in the Inspector.
Now I click in the scene to select an object for my editor's use, but now of course, the editor is no longer selected or my custom editor GUI visible.
This is obviously a nuisance as I would have to navigate back to my "manager" object every time.
Is there a way around this?
Thanks
Answer by Jamora · Nov 16, 2013 at 04:57 PM
The easiest way I can think of is to press the little lock icon on top of your custom inspector while your manager is selected. This locks the inspector so it won't change with the selection. Remember that you can open multiple inspector windows, so that you can see both the locked and the currently selected object.
A harder way would involve checking which object is selected in the OnInspectorGUI of your custom editor script and keeping that reference, but immediately changing the selected GameObject back to the manager. (see Selection) This would cause problems if you actually wanted to change the inspected object...
Thanks. The second method is something I'm going to try. In some Editors from the Asset Store, they are allowing clicking on objects or terrain with a shift-click. So maybe they are reverting the selection as you suggested, but only if the shift key is held down, therefore allowing normal selection with a simple click.
Your answer
Follow this Question
Related Questions
Initialising List array for use in a custom Editor 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Getting GUI.skin in editor script changed entire Unity Editor GUI 1 Answer
Reference a script from Editor folder 2 Answers