- Home /
copy/paste position into text editor
Hi,
is it possible to copy paste the 3 position (x,y,z) in one time and paste it in editor like notepad ? I always have to copy paste x, then y, then z :-( I know about copy paste the whole parameters in another object but that is not related.
Thanks
Answer by Jessespike · Dec 15, 2015 at 09:06 PM
Don't think there's a default way to do that. However, you could write an Editor script:
using UnityEngine;
using UnityEditor;
// Adds MenuItems to Unity Editor for copy/paste selected transform's position
public class CopyPositionEditor : ScriptableObject {
static Vector3 cachedPosition;
[MenuItem ("Edit/Copy Transform Position %#c")]
static void CopyPosition () {
if (Selection.activeTransform != null)
{
cachedPosition = Selection.activeTransform.position;
EditorGUIUtility.systemCopyBuffer = cachedPosition.x + ", " +
cachedPosition.y + ", " +
cachedPosition.z;
}
}
[MenuItem ("Edit/Paste Transform Position %#v")]
static void PastePosition () {
if (Selection.activeTransform != null)
{
Undo.RecordObject (Selection.activeTransform, "Paste Transform Position");
Selection.activeTransform.position = new Vector3(cachedPosition.x,
cachedPosition.y,
cachedPosition.z);
}
}
}
Thanks for your answer. First I'm not good enough to script something like this but that looks perfect. I tried this, created a C# (I think it is ? I only js) file butt here are the errors.
Assets/Editor/CopyPosition.cs(14,140): error CS1502: The best overloaded method match for string.String(char*)' has some invalid arguments Assets/Editor/CopyPosition.cs(14,140): error CS1503: Argument #1' cannot convert string' expression to type char*' Assets/Editor/CopyPosition.cs(14,36): error CS0122: `UnityEngine.GUIUtility.systemCopyBuffer' is inaccessible due to its protection level
Don't want to annoy, I'll try to find solutions but not sure to succeed.
I realized there was an error after posting. Try again, I updated the code.
Thanks, only
Assets/Editor/CopyPosition.cs(14,36): error CS0122: `UnityEngine.GUIUtility.systemCopyBuffer' is inaccessible due to its protection level
left, I'm looking on internet if I can solve this at least :x
That's odd, no error here. What version of Unity you running? I tested this with 5.2.2f1
Try this maybe:
EditorGUIUtility.systemCopyBuffer
4.6.3f1 for my version. I saw on internet that I have to make the function concerned public but I don't know where it is. I changed by your answer and now no more error ! Just have to find where is the menu now I can succeed in it I guess. Thanks again :v
it was at the end of the menu (I think I am a genious now that I found it even if it was clearly indicate in the code) It works perfectly and it will save me time and energy thanks very good answers/code.
O$$anonymous$$, thanks for verifying. I updated the code to now use EditorGUIUtility. Just in case someone else wants to use this in the future. Can you accept the answers as correct, so the question can be closed. Cheers.
Your answer
Follow this Question
Related Questions
Copy Transform 1 Answer
Efficiently mimic movements of GameObject 2 Answers
Problem with Instantiate 2D object to right position C# 1 Answer
Copying movement for period of time 2 Answers