Getting actor's relative rotation

I found out that the unexpected behavior of the inverse transform is caused by the gimbal lock. I solved this issue in C++ using only quaternions.