how to copy and manipulate a transform

Is there a way to set a variable as a copy of a transform? The following seems to make a reference to the actual transform, not duplicate the values of the transform into a new variable:
var thisTransform = transform;
var transformCopy = thisTransform;

when using Lingo in Director I could use:
someTransform = transform.duplicate()
Then from there go on to manipulate it, such as rotate, translate, scale, without manipulating the original. Is there anything like this within Unity? Thanks.

i don’t know if there’s a way to create a copy from it, but if not :

just create an Array function and store in it the 3 values of the transform .

Brilliant. Thank you! I was just starting to read up on Arrays when you posted that.

Now that I think about it, this seems to mitigate the ability to use something like:
myArray[1].Rotate(Vector3.up * Time.deltaTime, Space.World);
or
myArray[0].Translate(Vector3.up * Time.deltaTime, Space.World);

Maybe the only way to perform the built-in transform manipulators on a duplication of a transform is to actually create a new GameObject, set it’s transform values the same, then manipulate it.

If you are starting to read up on arrays, I worry that you are getting in over your head. Regarding your issues with references, it is important to understand the value types and reference types. If all you need is the transform’s position, just use a vector3 since transform.position is a vector3.

u can also Create functions , that create for u an empty gameobject, manipulate it, restore back the new datas then destroy it :slight_smile:

@crazyosachou: again, you are nearly prophetic, I was in the process of doing just that.

@JRavey: The reason behind the question is that I’ve run into a number of circumstances where I’d like to take a GameObject’s transform, manipulate it, then use the resulting values for various purposes, without ever affecting the original transform. I don’t mean to sound vague or cagey, I’m just trying to spare you a lengthy explanation of the silly experiments I’m working on unless it’s warranted. You stated I could just use a Vector3 variable to hold the value of transform.position, which is fine, until I need to perform a translate on that vector. As I understand it, a Translate will only work on an actual Transform type. More specifically, it’s Rotate that gets me stumped (after all I can easily do the math on a simple position Vector3 to calculate what a translate would do). Unless I’m working on a real transform, there doesn’t seem to be a way to use myRotationValueTypeVariable.Rotate(0,10,0); And since we’re dealing with Quaternions, I can’t just do simple math (at least what I consider simple math) on a Quaternion.

I’m crossing my fingers that I didn’t just confuse the heck out of this issue. Perhaps a specific example would help:
var thisRotation = Quaternion.LookRotation(somePosition) returns a rotation type value, that I then have contained within thisRotation . Without understanding Quaternions (inside and out as they say) I can’t go on to manipulate that variable further with the built-in tools (such as thisRotation.Rotate(x,y,z)) If however, I follow crazyosachou’s advise and actually make a whole new gameObject, I don’t need to understand the voodoo of Quaternions. After explaining all this, I’m wondering if I couldn’t just have said “how can I avoid directly manipulating Quaternions at all costs?” And thanks for taking the time, BTW.

Transform tmp_transform = Instantiate(transform); ?

pakfront, good idea. There’s a good chance my implementation of this is in error, but it looks like the “value” of tmp_transform becomes the instantiate, not the transform. In other words, if I try using tmp_transform.Rotate(0,1,0); in the Update function, it creates a new clone every frame. Or at least did once. Every thing I’ve tried after that froze and crashed Unity. Here’s what I had, and I recommend you NOT try this at home:

var tmp_transform : Transform;

function Awake(){
	var tmp_transform = Instantiate(transform);
	
}


function Update () {
	tmp_transform.Rotate(0,1,0);
	print(tmp_transform.rotation);
	
}

Thanks for trying!

but you forgot to destroy the object , the idea was :

Create an object , manipulate it , then STORE or RETURN its new Entries … and at the End Destroy the copy Destroy() ;

anyway, it depends on your idea and where u’ll use it … if u want more help, just explain ur thoghts …

Good luck

No, I think that will do it, I needed to destroy it. Thanks again.