Tranform.rotation issues


To keep things short I am assigning a transform.rotation from one object to another in a c# script using a method. The issue I am having is that one of the prefabs is rotated incorrectly. I have tried rotating the prefab and a transform that hold it but it’s always oriented the same way in game.

I have basically given up trying to fix the rotation in anywhere but the update so my question is how can I change the rotation of an object that is being updated to add 180 to the X and 90 to the Z? Is this even possible?

I didn’t find the underlying cause but I used a .transform,Rotate(x, y, z, Space.Self) and messed with the values until it was rotated properly. I was able to place this right after the update rotation.

It’s good practice to avoid modifying Prefabs through code so that you can always expect a prefab to have the same behavior every time you instantiate a new instance.

If you want to add a rotation to an object, then you need to multiple Quaternions together.

transform.rotation = transform.rotation * Quaternion.Euler(new Vector3(180, 0, 90));

If you want to set the rotation of an object, then same code just without the multiplication.

transform.rotation = Quaternion.Euler(new Vector3(180, 0, 90));