Performance Questions

Hey Guys,

Simple Question: What would be more efficient?

public class SpriteRotationLock : MonoBehaviour {
	
	private Transform spriteTransform;
	
	void Start() {
	
		spriteTransform = gameObject.transform;
		
	}
	
	void LateUpdate() {
	
		if(spriteTransform.rotation != Camera.mainCamera.transform.rotation)
			spriteTransform.rotation = Camera.mainCamera.transform.rotation;
		
	}
		
}

This

	void LateUpdate() {
	
		
		spriteTransform.rotation = Camera.mainCamera.transform.rotation;
		
	}

or this

        void LateUpdate() {
	
		if(spriteTransform.rotation != Camera.mainCamera.transform.rotation)
			spriteTransform.rotation = Camera.mainCamera.transform.rotation;
		
	}

ask yourself first if you really need this “if” check, then if you don’t need but you put it anyway that will be less efficient ^^.

Yeah, I would think that the check in this case would be slower then just setting it in this case. If you had more inside of the if statement, then it would warrant the if, but is a simple transfer of already in memory information. Also, why are you putting it in the late update? It’s not really needed there is it?

Thanks guys, I thought that was the case I just wasn’t sure if doing a compare was faster then doing a copy.

@Caliber
Its important when doing billboarding effects to do it in the lateupdate, well thats what a number of people have suggested on the forums anyway. As you always want it to face the camera you need to have it face the camera after all the transforms and rotations have been applied. If not it will always rotate a frame behind.