How to detect object being dragged in scene view or mouse down event?

We make a 2D platformer game and have a script which in edit mode snaps stuff to tilemaps making it a lot easier to place them in the levels. For various reasons it would help of this script could tell when an object is being dragged around in the scene. Is there any event for this? And if not, is it possible to tell if the mouse primary button is pressed on the object or at all in the scene view?

We have managed to detect this in OnSceneGUI() but is only called when gizmos are on and we need this to always work.

For unknown reasons Input.GetMouseButton() doesn’t seem to work in edit mode.

The ProBuilder package from Unity3D has a lot of heavy scene view interaction.

You should install it and take a look at the source code, see how they do it.

I actually found the SceneView.duringSceneGui event and in combination with Selection.objects it provided what I needed.

1 Like