Replace Yaw rotation in Quaternion without transofming quat to eulers

I have quaternion a and quaternion b. What i need to do is create quaternion c(eulerAx,eulerBy,eulerAz) but without transforming a and b to euler angles because when i do that i have gimbal lock problem :confused:

Any suggestions? I already look in every source for replacing yaw rotation in quaternion, clear yaw rotation in quaternion but i couldn’t find working solution :confused:

I going to take a shot at an answer based on on a fuzzy understanding of what you are attempting to do. ‘a’ and ‘b’ are the transform of the two objects:

var v1 : Vector3 = a.forward;
v1.y = 0.0f;
var v2 : Vector3 = b.forward;
v2.y = 0.0f;
var  q : Quaternion = Quaternion.FromToRotation(v1, v2) * a.transform.rotation;

Note this code will fail if the transform.forward of either a or b is aligned with the world ‘y’ axis.