I know these actions are available when right-clicking the Transform component, but wouldn’t it be 100% more convenient to have a small clickable button next to the “Position”, “Rotation” and “Scale” labels that would allow me to reset any of these vectors in one click? I use these actions A LOT, so it really bothers me that there is no quicker way to do it.
+1 for this feature.
+1, Might be a huge time saver.
Here is an editor extension that adds buttons next to the Transform input fields, to reset the position, rotation and scale:
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.Reflection;
namespace TheEditorToolboxProject
{
[CanEditMultipleObjects]
[CustomEditor(typeof(Transform))]
class TransformEditor : Editor
{
SerializedProperty m_LocalPosition;
SerializedProperty m_LocalRotation;
SerializedProperty m_LocalScale;
object m_TransformRotationGUI;
void OnEnable()
{
if (serializedObject == null)
return;
m_LocalPosition = serializedObject.FindProperty("m_LocalPosition");
m_LocalRotation = serializedObject.FindProperty("m_LocalRotation");
m_LocalScale = serializedObject.FindProperty("m_LocalScale");
if (m_TransformRotationGUI == null)
m_TransformRotationGUI = System.Activator.CreateInstance(typeof(SerializedProperty).Assembly.GetType("UnityEditor.TransformRotationGUI", false, false));
m_TransformRotationGUI.GetType().GetMethod("OnEnable").Invoke(m_TransformRotationGUI, new object[] { m_LocalRotation, new GUIContent("Rotation") });
}
public override void OnInspectorGUI()
{
var serObj = this.serializedObject;
if (serObj == null)
return;
serObj.Update();
DrawLocalPosition();
DrawLocalRotation();
DrawLocalScale();
DrawPropertiesExcluding(serObj, new string[] { "m_LocalPosition", "m_LocalRotation", "m_LocalScale" });
Verify();
serObj.ApplyModifiedProperties();
}
void DrawLocalPosition()
{
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.PropertyField(m_LocalPosition, new GUIContent("Position"));
if (GUILayout.Button(new GUIContent("0", "Reset Position"), EditorStyles.miniButton, GUILayout.Width(20)))
m_LocalPosition.vector3Value = Vector3.zero;
}
}
void DrawLocalRotation()
{
using (new EditorGUILayout.HorizontalScope())
{
m_TransformRotationGUI.GetType().GetMethod("RotationField", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new[] { typeof(bool) }, null).Invoke(m_TransformRotationGUI, new object[] { false });
if (GUILayout.Button(new GUIContent("0", "Reset Rotation"), EditorStyles.miniButton, GUILayout.Width(20)))
m_LocalRotation.quaternionValue = Quaternion.identity;
}
}
void DrawLocalScale()
{
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.PropertyField(m_LocalScale, new GUIContent("Scale"));
if (GUILayout.Button(new GUIContent("1", "Reset Scale"), EditorStyles.miniButton, GUILayout.Width(20)))
m_LocalScale.vector3Value = Vector3.one;
}
}
void Verify()
{
var transform = target as Transform;
var position = transform.position;
if (Mathf.Abs(position.x) > 100000f || Mathf.Abs(position.y) > 100000f || Mathf.Abs(position.z) > 100000f)
EditorGUILayout.HelpBox("Due to floating-point precision limitations, it is recommended to bring the world coordinates of the GameObject within a smaller range.", MessageType.Warning);
}
}
}
#endif
I don’t think this should be the part of the standard UI, it’s crowded enough already and it provides the proper means to do the job.
Thanks a lot for this! I’ve been using a similar script since I’ve seen this being used in NGUI. Your script is so much cleaner solution than what I’ve been using previously, so I’ll start using your script instead!
I think a lot of people are missing out when not using something like this. Most of the user base probably doesn’t even know that these actions can be implemented in such an accessible way. I really think this should be in Unity by default.
wait didn’t they have a reset button on the left side of each transform component, it’s an “R” button i think. is this removed?
Thats a plugin
Tab 0 tab 0 tab 0 is fast enough
Now do that for rotation and position, you got 6 times. And maybe you have few objects as well …
Pure productive fun
no it’s not a plugin, but it got removed i think. And it’s PRS apparently not R
If you have it on a few objects just select of all of them and do it once
Pretty sure this is the NGui plugin. Not seen those buttons in native Unity before
weird, i’m not using NGUI
That definitely looks like NGUI. If you’re not using NGUI, there was a script floating around that was adding these buttons just like NGUI did, and it looked just like this. I was using it myself, so you probably have it somewhere in your project.
yeah probably, i just don’t remember what was i put in my project
Access Deny
Updated my post and added the code, see here
This is perfect @Peter77 , Thanks a lot. Can we get this as a built in feature?, would be a good QOL addition i think
EDIT : hmmm i just realized it changed the Contraint Proportion Buttons. . . .