Transform copy procedure

In the editor, I've got game objects that when placed in the world, during their Gizmo calls will orient themselves to the next game object in a list (think bread crumb trail where the bread pieces point to the next bread piece in the trail).

I've got code to do this:

        PathNode node = nextNode;
        if (node != null)
        {
            GameObject obj = node.gameObject;
            Gizmos.DrawLine(transform.position, obj.transform.position);

            // aim the node at the next node. 
            transform.LookAt(obj.transform);
        }

And it works, BUT it always marks the scene dirty. What I want is to get the rotation that the current node should be and compare it to its real rotation; if different, then update. If not, don't update it so the scene won't be perptually marked dirty.

To that end, I was hoping to do something like this:

        PathNode node = nextNode;
        if (node != null)
        {
            GameObject obj = node.gameObject;
            Gizmos.DrawLine(transform.position, obj.transform.position);

            // aim the node at the next node. 
            Transform t = new Transform(transform);
            t.LookAt(obj.transform);

            if (t.rotation != transform.rotation)
            {
                 transform.LookAt(obj.transform);
             }
        }

However, I can't find anyway to make a copy of a transform that I can apply a LookAt() to. Is there any way to do this?

Thanks.

You can't instantiate a Component, you're not even supposed to call its constructor. But you don't need to either. You can use the Quaternion class to create a rotation and compare that to your transform.rotation.

http://unity3d.com/support/documentation/ScriptReference/Quaternion.LookRotation.html

Vector3 direction = obj.transform.position - transform.position;
if (transform.rotation != Quaternion.LookRotation(direction, Vector3.up)
  //do something

It's not possible to copy a transform at all In this case though, it's a moot point - you should check Quaternion.LookRotation

Something along the lines of this should do the trick:

Quaternion rot = Quaternion.LookRotation(obj.transform.position - transform.position);
if (rot != transform.rotation) transform.rotation = rot;

Though i would be careful with doing Quaternion equality checks like that, perhaps using something like this instead:

Quaternion rot = Quaternion.LookRotation(obj.transform.position - transform.position);
if (Mathf.Abs(Quaternion.Angle(rot, transform.rotation) > threshold)) transform.rotation = rot;

where threshold is how much leniency you'll give it in degrees