Matrix4x4.SetTRS() getting "Assertion failed on expression: 'ValidTRS()'"

I was trying to use the U3D API Matrix4x4.rotation to replace my.

private Matrix4x4 m_Matrix;
public Vector3 position
{
    get { return m_Matrix.GetColumn(3); }
    set { m_Matrix.SetTRS(value, rotation, Vector3.one); m_Dirty = true; }
}
public Quaternion rotation
{
    get
    {
#if UNITY_2018
        return m_Matrix.rotation;
#else
        Vector4
        lhs = m_Matrix.GetColumn(2),
        rhs = m_Matrix.GetColumn(1);
        if (lhs == Vector4.zero && rhs == Vector4.zero)
            return Quaternion.identity;
        else
            return Quaternion.LookRotation(lhs, rhs);
#endif
    }
    set { m_Matrix.SetTRS(position, value, Vector3.one); m_Dirty = true; }
}

the purpose of above code are using Matrix4x4 to cache the position & rotation and use it to perform the MultiplyPoint3x4() calculation.

I don’t think there was an error hidden within, since I already using that class for half year.
the only thing I did within this month, was using the Matrix4x4.rotation to replace my ugly code.
watch the tag ‘UNITY_2018’ that was the change.

I would like to know if I did anything wrong for above code.
here is the result run on my computer.

5182247--514745--matrix_rotation_error.gif

the code I found most likely to trigger above error was this.

CapsuleData capsule = sweepReport.capsule;
Debug.Log($"Pos:{sweepReport.suggestedPosition} Quat:{capsule.rotation}");
capsule.position = sweepReport.suggestedPosition;

and I can confirm the previous version (on #else session) that I’m using is working fine.
perhaps I’m hidden error ? can anyone explain to me thank you.

I think I found it… the mistake hidden in my code.
it’s related to this.
Quaternion To Matrix conversion failed because input Quaternion is invalid {0.000000, 0.000000, 0.000000, 0.000000} l=0.000000

1 Like