Gimbal lock issue: maintaining consistent Euler angles with Gizmo and UI

Hi everyone! I’m using a translator, so I apologize if my English isn’t perfect!

I’m currently working on something that allows users to manipulate rotations through the UI and with a gizmo (similar to how it works in the Editor).

My problem is with handling Euler angles. Quaternions are difficult for users to understand, so I’m using Euler angles for input. However, I’m encountering the classic gimbal lock issue: when the Pitch goes beyond 90 degrees, Yaw and Roll jump to -180 degrees.

I’ve addressed this known issue by creating a new parameter called _customEulerAngle to store the desired Euler angles. This works well for UI-based rotations.

However, a new problem arises when I rotate the object using the Gizmo. The Gizmo uses setRotation to apply the rotation. When I try to update _customEulerAngle based on the Quaternion used in setRotation, the values become incorrect again due to the gimbal lock.

Is there a way to use both setEulerAngles (for UI input) and setRotation (for Gizmo manipulation) while also keeping _customEulerAngle synchronized correctly?