Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'Scripting' started by canis, Nov 16, 2019.

  1. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    79
    I was trying to use the U3D API Matrix4x4.rotation to replace my.

    Code (CSharp):
    1. private Matrix4x4 m_Matrix;
    2. public Vector3 position
    3. {
    4.     get { return m_Matrix.GetColumn(3); }
    5.     set { m_Matrix.SetTRS(value, rotation, Vector3.one); m_Dirty = true; }
    6. }
    7. public Quaternion rotation
    8. {
    9.     get
    10.     {
    11. #if UNITY_2018
    12.         return m_Matrix.rotation;
    13. #else
    14.         Vector4
    15.         lhs = m_Matrix.GetColumn(2),
    16.         rhs = m_Matrix.GetColumn(1);
    17.         if (lhs == Vector4.zero && rhs == Vector4.zero)
    18.             return Quaternion.identity;
    19.         else
    20.             return Quaternion.LookRotation(lhs, rhs);
    21. #endif
    22.     }
    23.     set { m_Matrix.SetTRS(position, value, Vector3.one); m_Dirty = true; }
    24. }
    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.

    matrix_rotation_error.gif

    the code I found most likely to trigger above error was this.
    Code (CSharp):
    1. CapsuleData capsule = sweepReport.capsule;
    2. Debug.Log($"Pos:{sweepReport.suggestedPosition} Quat:{capsule.rotation}");
    3. 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.
     
  2. canis

    canis

    Joined:
    Oct 25, 2013
    Posts:
    79
    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
     
    BigRookGames likes this.