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

Question Correct was to Translate in an IJobChunk, in 1.0?

Discussion in 'Entity Component System' started by PublicEnumE, Nov 2, 2022.

  1. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    Unity reworked how Transform data works in Entities 1.0. The old Position, Rotation, LocalScale Components have been removed and replaced by the new TransformAspect.

    But using Aspects isn't supported in IJobChunk jobs, so it's unclear how Unity intends for users to manipulate an Entity's transform from inside of an IJobChunk job.

    Some people have figured out that they can add the source generated TransformAspect.TypeHandle to their jobs as a workaround, though this seems a bit like a user-discovered hack. The pattern doesn't match how we're meant to use any other Component types in IJobChunks, and it doesn't work the same way for other Aspect types. It is possible for you to wait for Unity to generate the 'TypeHandle' member of your own custom Aspects, and then to use that in an IJobChunk, but that also feels like a bit of a user-discovered hack - an accidental byproduct of how Aspect generation needed to work, rather than an intended workflow.

    I'm looking for some guidance from Unity devs about what the intended workflow is to Translate an Entity in an IJobChunk now. How did they plan that this should work, when they decided to change Transforms?

    Thank you for any advice!
     
    Last edited: Nov 2, 2022
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    TransformAspect
    is just a sytax sugar wrapper, look at it's internals and you'll see what it's using. If you want translate by yourself, just use
    LocalToWorldTransform : IComponentData
    directly in user friendly manner, which is exactly what responsible for translation rotation and scale now (and parent relations through
    LocalToParentTransform
    ,
    ParentToWorldTransform
    if required). It contains
    UniformScaleTransform
    struct with position, uniform scale, rotation you can modify directly and bunch of handful methods.
    upload_2022-11-2_16-25-46.png

    upload_2022-11-2_16-25-35.png
     
    PublicEnumE likes this.
  3. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    Thank you - that's exactly what I was looking for. Really appreciate it - my ability to dig into the 1.0 source code has been limited lately, and I really appreciate the help.