Does it help performance to first check if some transform attribute has changed before setting it?

If inside an Update you set an object’s position, but the position might not always be changing, does it make any difference at all whether or not you redundantly set the position to the value it already is?

i.e. Does this save you anything?

void Update()
{
    Vector3 nextPosition = new Vector3(x, y, z);

    if (transform.position != nextPosition)
    {
        transform.position = nextPosition;
    }
}

Compared to this:

void Update()
{
    Vector3 nextPosition = new Vector3(x, y, z);

    transform.position = nextPosition;
}

Setting the position every frame has really almost no effect of performance, for a computer of our age

@Llama_w_2Ls

Try to move hundreds of entities every frame and I can guarantee you will see a drop of your FPS.

There is no absolute yes or no to this question.

IT DEPENDS.

If the object you move has a complex hierarchy, moving it to a different position can affect performances. If it has many parents, the local position must be computed according to the hierarchy to match the desired world position.

Changing a canvas element dirties the whole canvas (position, color, animation, …, ANYTHING)

I did a check with the following code:

float x;

void Update()
{
    if(Input.GetKeyDown(KeyCode.Space))
    {
        x += 0.1f;
    }

    transform.position = new Vector3(x, 0, 0);

    if(transform.hasChanged)
    {
        Debug.Log("Has changed");
        transform.hasChanged = false;
    }
}

The flag hasChanged does not turn to true unless I’m pressing space, so I guess Unity does some optimisation to avoid unnecessary computation if the new position is the same as the old one. Meaning your check may not be needed.

I highly advise you to profile your game instead of trying to optimise things without knowing if it will have any effect.