Search Unity

Bug Quaternion inspector broken

Discussion in 'Editor & General Support' started by crowmaster, Nov 8, 2022.

  1. crowmaster

    crowmaster

    Joined:
    Jul 6, 2012
    Posts:
    83
    I am using Unity 2020.2.4 and from some time all quaternions in my project started to look like this. This screen is from empty project with only script is this one. As you can see, instead of Euler angles representation they are now drawn as their XYZW values. Reinstalling Unity not solved the problem neither is deleting Library folder.
    Problem only appears in this specific Unity version.
    upd: 2019.4.33 also has this problem, 2020.2.33 does not
    upload_2022-11-8_12-53-17.png
     
    Last edited: Nov 8, 2022
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    This is a quaternion and is how it should show. A quaternion simply has 4 values.
    It showing 3 in another is an issue of that version, not the right one.
    If you want to see euler angles, simply make a vector3 and add the euler angles to that in Update
     
  3. crowmaster

    crowmaster

    Joined:
    Jul 6, 2012
    Posts:
    83
    Sry but you are mistaken here. Unity was always showing quaternions in inspector as 3 Euler angles for convenience.
    How you supposed to deal with raw quaternion values anyway? They are not human readable unlike angles.
    Quaternion showing as four values is not an intended behavior its a bug.
    upload_2022-11-8_14-34-42.png
    Here is a screen from Unity 2022 and it is how it supposed to look like
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    Personally don't really agree if you serialise it in script, as it could complicate things if you actually use quaternions. If you think it's a bug file a bug report
     
  5. crowmaster

    crowmaster

    Joined:
    Jul 6, 2012
    Posts:
    83
    Quaternions are serialized as their four raw values. But when showing in inspector they are converted into Euler representation for convenience. This does not really change the way they stored.
    I can't file a bug report because this only happens on my machine, i am trying to figure how to repair Unity but without much success.
     
  6. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    If it only happens for you update to the latest version you can and delete the library folder?
     
  7. crowmaster

    crowmaster

    Joined:
    Jul 6, 2012
    Posts:
    83
    I can upgrade to new Unity version and it should fix the issue, but i prefer to keep this as last resort, cause there is at least one nasty bug introduced in a newer Unity versions i better not deal with.
     
  8. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    Which bug?
    And if you dont want to upgrade make a custom inspector
     
  9. crowmaster

    crowmaster

    Joined:
    Jul 6, 2012
    Posts:
    83
    Before the 2021 release Unity editor console was working both in editor and when connected to standalone development build perfectly. In 2021 and onward it now works incorrectly from builds.
     
  10. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    Interesting. In the latest 2021 lt works for me if I use autoconnect profiler
     
  11. crowmaster

    crowmaster

    Joined:
    Jul 6, 2012
    Posts:
    83
    Maybe they finally fixed it after all, not checked latest version. I very much hope they did.
     
    DevDunk likes this.
  12. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    @crowmaster Did you conclude with anything here?

    I upgraded to Unity 2022 and encountered this myself now, but this seems to differ from your experience?

    I tested this in all my installed versions of Unity and these are my results:

    2022.2.0f1: X, Y, Z, W fields in inspector (I tested 2022.2.1f1 as well because I thought this was a new bug introduced in 2022.2, but it was the same)
    2021.3.15f1: X, Y, Z
    2020.3.42.f1: X, Y, Z
    2019.4.38f1: X, Y, Z, W
    2018.4.36f1: X, Y, Z, W

    I've never actually thought about this before to be honest so I actually can't say what's the intended result here, but one of them is clearly wrong? I would assume it's the X, Y, Z, W result that's wrong because like you hint at how am I supposed to enter values there manually? The reason I noticed this now was because I'm copying some values from a sample project made in 2021, but my own project is using 2022 and I'm not able to manually set rotations the same way they have done in that project because I can't set quaternions manually in the inspector like this...

    I can't find any information in any release notes about this being changed/fixed between Unity versions either.
     
  13. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    This script fixes the problem for me:
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. [CustomPropertyDrawer(typeof(Quaternion))]
    5. public class QuaternionPropertyDrawer : PropertyDrawer
    6. {
    7.     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    8.     {
    9.         EditorGUI.PropertyField(position, property, label);
    10.     }
    11. }
    Just add that code to a script in an Editor folder and Quaternions will show as X, Y, Z again. I have very little experience with property drawers, but from what I can tell the only thing I'm doing is just outputting the GUI that should have been there all along? So I'm guessing there is a bug where in certain situations or versions of Unity the correct property drawer isn't being used for Quaternions?
     
    Last edited: Dec 26, 2022
  14. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,443
    They're not as completely inscrutable as you might think. The X Y Z components describe the axis of rotation, and the W describes the amount of twist around that axis from 0 to 1. They have to be a unit vector as a Vector4, so the more W twist you get, the shorter the X Y Z magnitude as a Vector3 must be. You're right that you really shouldn't be editing them as individual parts, unless you are able to do the normalization.
     
  15. Deleted User

    Deleted User

    Guest

    URP contains a QuaternionPropertyDrawer that will change the quaternion from the 4 xyzw values into the euler angles.
     
  16. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,190
    But at that point is it still a quaternion? :p
     
    Deleted User likes this.
  17. Deleted User

    Deleted User

    Guest

    Ideally, I'd expect the URP package to make a namespaced property attribute and set the property drawer to that attribute, rather than overriding all the quaternion inspectors.

    Though, most of the time, I don't want to edit the quaternion components by hand. Instead, I'd rather edit them using a screen space handle, or angle/axis, or euler angles. Even though I like the mathematical properties of quaternions, my intuitive interpretation of rotations is not a quaternion.