if statement or just setting transform.position?

(I feel like somewhere this question must have been asked, I just can’t seem to find the answer, so if someone can redirect me to the answer I’ll gladly delete the question.)

I have this code in a little gizmo I’m making, inside the update function:

if (transform.position.x != transform.parent.position.x)
	{
		transform.position.x = transform.parent.position.x;
	}

Is there any point in the if statement here? Does checking if the positions are the same actually have a performance hit the same as just assigning the position every frame?

Thanks!

There’s no point in checking. Beyond that, accessing a game object’s transform has a hidden GetComponent() call. So, in addition to accessing the variable twice, you are also calling GetComponent() twice. The usual way around the GetComponent() call is to get it once in Start(), and then use your class instance variable.