TransformSaver broken in 1.5.1?

At Ulgonep’s advice, I’m trying out the TransformSaver script to copy the transform information from one of my water instances to another one.

All of the alert messages say that the transform has been saved and then applied properly, but the target instance in the scene doesn’t change.

Is there something I’m overlooking? (The script itself seems to have installed and compiled correctly).

Thanks,
Steve

The script doesn’t do quite that.

What it does is record the current position, scale, rotation of selected objects. Then later you can select “Apply Saved Transforms” (and you don’t have to have anything selected) and those recorded transform informations will be applied back to those objects you selected.

It’s useful for letting the physics engine position things and then applying that back to your actual scene.

It’s kind of confusing, so if anyone has an idea on how to make it better please chime in and I may see about fixing it.

What you would like to do is very possible too, I just don’t think there is a script on the wiki to do it right now.

Cheers,
-Jon

Jon, would it be a matter of changing the functions to work with one object at a time and then to change the apply function to target the currently selected object instead of the old one?

It’d be a simpler script. In the record/copy function, you would record the localPosition, localScale, and localRotation of something like Selection.activeTransform into some static data structure. (Three static Vector3 would be just fine.)

Then in the apply/paste function, you would set the localPosition, localScale, and localRotation of something like Selection.activeTransform to the values contained in your stored static variables.

Shouldn’t be more than a few lines for each function. Probably more work here to type this post, but I think it’d be advantageous to just try it and come back if you hit a wall.

-Jon

Jon, I did it! My first real Unity script and my first C# script:

using UnityEngine;
using UnityEditor;
using System.Collections;
 
public class TransformCopier : ScriptableObject
{
        private static Vector3 position;
        private static Quaternion rotation;
        private static Vector3 scale;
        private static string myName; 
    
    [MenuItem ("Custom/Transform Copier/Copy Transform")]
    static void DoRecord()
    {
       position = Selection.activeTransform.localPosition;
       rotation = Selection.activeTransform.localRotation;
       scale = Selection.activeTransform.localScale;
       myName = Selection.activeTransform.name;       
        
        EditorUtility.DisplayDialog("Transform Copy", "Local position, rotation,  scale of "+myName +" copied relative to parent.", "OK", "");
    }
 
    [MenuItem ("Custom/Transform Copier/Paste Transform")]
    static void DoApply()
    {
        Selection.activeTransform.localPosition = position;
        Selection.activeTransform.localRotation = rotation;
        Selection.activeTransform.localScale = scale;      
        
        EditorUtility.DisplayDialog("Transform Paste", "Local position, rotation, and scale of "+myName +"  pasted relative to parent of "+Selection.activeTransform.name+".", "OK", "");
    }
}

This does what I need it to, but it has no error checking to make sure that there’s an object selected, or to warn you if you can’t do what it says it’s going to do.

For some reason, the two commands are also reversed in order in the menu. I’m not sure why.

I’ve put it in the wiki, too.
http://www.unifycommunity.com/wiki/index.php?title=CopyTransform

Thanks a lot for your hints.

Great to hear you got it going!

Hope it opens doors for future script ideas.

-Jon

How about a Select unused assets one? For the project window
Ive installed all those wizard scripts, and theyre great-Cheers Jon!
I highly recommend them to everyone
AC

I’d love that too, but I can’t think of a way to do that. Don’t have the right hooks in UnityEditor as far as I know.

-Jon