- Home /
Intercepting left click in scene view for Custom editor.
I am trying to intercept the left click event when editing a component in the scene view. The editor is supposed to add a way point on the scene whenever the user clicks however it seems to add the waypoint as expected then switch the focus to the gameObject that was underneath the mouse cursor. Is it possible to intercept the click action to not switch to another gameObject?
The Events I am using are as follows:
void OnSceneGUI()
{
if (Event.current.type == EventType.MouseDown)
{
// Add waypoint logic...
Event.current.Use();
}
}
I have also tried MouseUp and both MouseUp and MouseDown with Event.current.Use to no avail. Is it also possible to specify which mouse button the event corresponds to?
Answer by testure · Nov 04, 2013 at 04:09 AM
Unity treats gameobjects as hot controls (internally) so they can be interacted with. If you override the hot control, it keeps the user from being able to select game objects:
void OnSceneGUI()
{
if (Event.current.type == EventType.Layout)
{
HandleUtility.AddDefaultControl(0);
}
}
Your answer
Follow this Question
Related Questions
I want switch Mouse's navigation in SceneView 0 Answers
Capture input events before scene view does? 0 Answers
Can't move GameObject in Scene view with Unity Components attached 2021.2.2f 0 Answers
What exactly is the purpose of the scene's draw mode Alpha Channel 1 Answer
Handles.ScaleValueHandle and values < 0 0 Answers