Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Built in aspects gone?

Discussion in 'Entity Component System' started by Heptagram064, Mar 24, 2023.

  1. Heptagram064

    Heptagram064

    Joined:
    Feb 22, 2022
    Posts:
    94
    Hello,

    So i am new to unity ECS (using 1.0.0-pre.65), have been following some tutorials, and it seems to appear that there were supposed to be some default built-in aspects that come with certain authored gameobject-components to make life easier (e.g. a TransformAspect to handle changing a transform like one would expect, instead of 5D quaternion mess when trying to rotate something).
    5D Quaternion.gif

    These aspects seem to be removed? Cant seem to find them anywhere. Are we now supposed to make our own aspects to use unity's built in components, or am i missing something?
     
  2. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    825
    Yeah transformaspect seems to be one of the casualties of the recent transform changes. There was a good explanation over on the unity discord(not a bad resource to have at your fingertips)
    You can still make your own aspects, LocalTransform should suffice in most uses though.

    Discordtransformchanges.png
     
    UniqueCode and andrew-lukasik like this.
  3. Heptagram064

    Heptagram064

    Joined:
    Feb 22, 2022
    Posts:
    94
    So i am supposed to write my own aspect, in order to fix rotation, until unity patches it in the next pre- version?
     
  4. Heptagram064

    Heptagram064

    Joined:
    Feb 22, 2022
    Posts:
    94
    Also, cant seem to find "DOTS General Discussion" on the official unity discord, can you give me a link?
     
  5. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    825
    I'm really as far from an expert on quaternions as anyone could possibly be, but my assumption is this is normal when modifying a quaternion, perhaps you were expecting euler angle based rotations in the inspector(like a gameobject has)? Just for the record I never actually had a chance to use the transform aspect before it was removed, so not sure if it had euler rotations inside of it.
    You could make your own component where a system takes an euler rotation and overwrites the existing rotation of localtransform.

    Scroll down under scripting to find the dots-forum area

    https://discord.com/invite/unity

    firefox_Uf6hqZ6oF2.png
     
  6. Heptagram064

    Heptagram064

    Joined:
    Feb 22, 2022
    Posts:
    94
    It most definitely is no normal quaternion behaviour. Modifying a proper quaternion gives rotation only, not scale.

    I just hope unity patches this soon
     
    Last edited: Mar 24, 2023
  7. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    825
    Actually I see someone else complaining on discord(and a dev mentioning a fix on the way) about the same rotation scaling so yeah I definitely know nothing of quaternions!
     
  8. Heptagram064

    Heptagram064

    Joined:
    Feb 22, 2022
    Posts:
    94
    This is the same discord i found. But for some reason i dont see the dots parts... I suspect it to be the fact i need to "complete some steps before you may chat", but for that i need to give a phone number. Hella aint going to do that, thx anyway.
     
  9. scottjdaley

    scottjdaley

    Joined:
    Aug 1, 2013
    Posts:
    152
    Huh, I don't remember doing that. Probably to stop bots from joining and spamming the server. Unfortunately, that is where a lot of the DOTS discussion happens and the best place to get quick help.

    Not sure what quaternion issue you are talking about, but the one mentioned on the discord is how the
    LocalToWorld.Rotation
    property returns the wrong value if the entity is scaled in any way. A quick fix is to create an extension method for LocalToWorld that normalizes the quaternion:

    Code (CSharp):
    1. public static quaternion Rotation(this LocalToWorld ltw) =>
    2. quaternion.LookRotationSafe(ltw.Forward, ltw.Up);
    More info in this thread: https://forum.unity.com/threads/localtoworld-rotation-affected-by-entity-scale.882133/
     
  10. Heptagram064

    Heptagram064

    Joined:
    Feb 22, 2022
    Posts:
    94
    As you can clearly see in the supplied GIF, my issue isn't the rotation being slightly off when the object is scaled, but the fact that changing the rotation scales the object in a weird manner. Think ill be waiting for a patch tho, instead of trying to get a workaround (Quaternions aren't supposed to space out scale on default in my oppinion). Thanks anyway.
     
  11. scottjdaley

    scottjdaley

    Joined:
    Aug 1, 2013
    Posts:
    152
    Sorry, I actually didn't realize that was a gif, I thought it was a screenshot about the lack of aspects.

    Manually modifying one component of a quaternion will result in scale and shear. This is because the result needs to be normalized.

    I think you might be confusing quaternions with euler angles. With euler angles, the "x" component represents the amount the object was rotated around the x axis. Likewise for y and z. With euler angles, you can manually override the value and it will update in a mostly intuitive way without and scaling or shearing artifacts. However, while euler angles are nice for debugging and manual editing, they have a couple of problems that make them unsuitable for runtime rotation information. The first issue is that euler angles have to be applied in a specific order, and that order is not really intuitive to the user. The other issue is known as "gimbal lock" where a degree of freedom is lost in certain configurations.

    Quaternions fix all these problems, but are harder to work with manually. Generally, if you want to change an object's rotation quaternion, you'll want to use methods like the following:

    Code (CSharp):
    1. quaternion.Euler()
    2. quaternion.RotateX()
    3. quaternion.RotateY()
    4. quaternion.RotateZ()
    5. quaternion.AxisAngle()
    6. quaternion.LookRotationSafe()
    Btw, the Euler method lets you choose which order the axis rotations are applied.
     
  12. scottjdaley

    scottjdaley

    Joined:
    Aug 1, 2013
    Posts:
    152
    Another option is to switch the inspector to show authoring data instead of runtime data. Then you can rotate the authoring game object's transform component (which shows euler angles) and it will rotate the baked entity without scaling or shearing.
     
    apkdev likes this.
  13. Heptagram064

    Heptagram064

    Joined:
    Feb 22, 2022
    Posts:
    94


    I am aware that changing components on a quaternion does not work like eulers. It's just that any other 3D program using quaternion are apparently already normalised, for i never encountered scale and shear using them. Which means i just don't know how quaternion work, in raw math lol...

    In my case i rarely change transforms manually during play-test runtime, and if so, yes using the authoring components. I'ts just also nice to know how to properly rotate something from script.
    Thanks for telling me ^.^
     
    scottjdaley likes this.
  14. scottjdaley

    scottjdaley

    Joined:
    Aug 1, 2013
    Posts:
    152
    Nobody really knows how quaternions work
     
    Heptagram064 and Rukhanka like this.
  15. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    Nah, they’re pretty simple after you learn them
    upload_2023-3-25_12-34-21.png
    )
     
    scottjdaley and dwulff like this.
  16. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    284
    The best explanation on quaternions I could ever find was the color theory one.