Version: 5.4 beta (switch to 5.3)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Handles.FreeMoveHandle

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function FreeMoveHandle(position: Vector3, rotation: Quaternion, size: float, snap: Vector3, capFunc: Handles.DrawCapFunction): Vector3;
public static Vector3 FreeMoveHandle(Vector3 position, Quaternion rotation, float size, Vector3 snap, Handles.DrawCapFunction capFunc);

Parameters

position The position of the handle.
rotation The rotation of the handle. this defines the space along.
size The size of the handle.
capFunc The function to use for drawing the handle, eg, Handles.RectangleCap

Note: Use HandleUtility.GetHandleSize where you might want to have constant screen-sized handles.
snap The grid size to snap movement to.

Returns

Vector3 The new value modified by the user's interaction with the handle. If the user has not moved the handle, it will return the same value as you passed into the function.

Description

Make an unconstrained movement handle.

This can move freely in all directions. Hold down CMD to snap, CMD-SHIFT to raysnap agains colliders in the scene.


Free Move handle in the Scene View.

#pragma strict
// Name this script "FreeMoveEditor"
@CustomEditor(FreeMove)
@CanEditMultipleObjects
public class FreeMoveEditor extends Editor {
	public function OnSceneGUI() {
		var t: FreeMove = (target as FreeMove);
		EditorGUI.BeginChangeCheck();
		var pos: Vector3 = Handles.FreeMoveHandle(t.lookAtPoint, Quaternion.identity, .5f, new Vector3(.5f, .5f, .5f), Handles.RectangleCap);
		if (EditorGUI.EndChangeCheck()) {
			Undo.RecordObject(target, "Free Move LookAt Point");
			t.lookAtPoint = pos;
			t.Update();
		}
	}
}
// Name this script "FreeMoveEditor"
using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(FreeMove))] [CanEditMultipleObjects] public class FreeMoveEditor : Editor { public void OnSceneGUI() { FreeMove t = (target as FreeMove);

EditorGUI.BeginChangeCheck(); Vector3 pos = Handles.FreeMoveHandle(t.lookAtPoint, Quaternion.identity,.5f,new Vector3(.5f,.5f,.5f),Handles.RectangleCap); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Free Move LookAt Point"); t.lookAtPoint = pos; t.Update(); } } }

And the script attached to this handle:

#pragma strict
// Name this script "FreeMove"
@ExecuteInEditMode
public class FreeMove extends MonoBehaviour {
	public var lookAtPoint: Vector3 = Vector3.zero;
	public function Update() {
		transform.LookAt(lookAtPoint);
	}
}
// Name this script "FreeMove"
using UnityEngine;
[ExecuteInEditMode]
public class FreeMove : MonoBehaviour
{
    public Vector3 lookAtPoint = Vector3.zero;

public void Update() { transform.LookAt(lookAtPoint); } }