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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Entities Graphics 1.0.0-pre.65 The TransformAspect is gone. How do I replace it

Discussion in 'Entity Component System' started by Yt1607388033, Mar 25, 2023.

  1. Yt1607388033

    Yt1607388033

    Joined:
    Mar 25, 2022
    Posts:
    3
    I am new to DOTS and find that TransformAspect no longer exists.

    Problems to be solved:

    When moving an object, I wrote how to change the position of the object in the foreach statement of MovingSystem. I hope you can provide an example code for changing the position, thank you!


    public partial class MovingSystemBase : SystemBase
    {
    protected override void OnUpdate()
    {
    foreach (TransformAspect transformAspect in SystemAPI.Query<TransformAspect>())
    {
    //TODO How to write the code here
    //transformAspect.Position += new float3(SystemAPI.Time.DeltaTime, 0, 0);
    }
    }
    }
     
  2. Yt1607388033

    Yt1607388033

    Joined:
    Mar 25, 2022
    Posts:
    3
    public partial class MovingSystemBase : SystemBase
    {
    protected override void OnUpdate()
    {
    //TODO How to write the code here
    //foreach (TransformAspect transformAspect in SystemAPI.Query<TransformAspect>())
    //{
    //transformAspect.Position += new float3(SystemAPI.Time.DeltaTime, 0, 0);
    //}
    }
    }
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,647
    For the most part, just use LocalTransform
     
  4. Yt1607388033

    Yt1607388033

    Joined:
    Mar 25, 2022
    Posts:
    3
    Just now, my version is back to Entities Graphics 1.0.0-pre-44 and then upgraded to Entities Graphics 1.0.0-pre-65. I suddenly found that it is OK again. Thank you for your answer
     
  5. RoHofmann

    RoHofmann

    Joined:
    Aug 15, 2017
    Posts:
    15
    I tried to do that like this:

    Code (CSharp):
    1. foreach (LocalTransform localTransform in SystemAPI.Query<LocalTransform>())
    2.             {
    3.                 localTransform.Position += SystemAPI.Time.DeltaTime * new float3(1, 0, 0);
    4.             }
    but I get the error that I cannot modify the members of localTransform as it is a foreach iteration variable.
     
  6. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    299
    Use
    RefRW<LocalTransform>
    instead of a value copy.

    I.e.:
    foreach (var localTransform in SystemAPI.Query<RefRW<LocalTransform>>())


    Then modify the position via:
    localTransform.ValueRW.Position += SystemAPI.Time.DeltaTime * new float3(1, 0, 0);
     
    elliotc-unity likes this.
  7. RoHofmann

    RoHofmann

    Joined:
    Aug 15, 2017
    Posts:
    15
    Thanks, I knew that I had to get a ref in there somehow, but didn't now how :)
     
  8. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    820
    Problem here being the main reason the TransformAspect was useful though, that of manipulating the transform of entities in a hierarchy. Correct me if I'm wrong, but adjusting the LocalTransform on a child can cause things to get out of sync with the more complicated hierarchy which is what TransformAspect handled for us. Unless LocalTransform now also handles that?