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 What can I use to replace TransformAspect?

Discussion in 'Entity Component System' started by SlumberPenguin, Apr 7, 2023.

  1. SlumberPenguin

    SlumberPenguin

    Joined:
    Sep 20, 2020
    Posts:
    25
    It was removed in pre.65, so, How do i replace it? please give me a complete complete code, thanks
     
    hughperkins likes this.
  2. DatCong

    DatCong

    Joined:
    Nov 5, 2020
    Posts:
    77
    Use TransformComponent
     
  3. SlumberPenguin

    SlumberPenguin

    Joined:
    Sep 20, 2020
    Posts:
    25
    I wrote that but nothing happened
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.Entities;
    5. using Unity.Transforms;
    6. public partial class MovingSystemBase : SystemBase
    7. {
    8.     protected override void OnUpdate()
    9.     {
    10.         foreach (LocalTransform trans in SystemAPI.Query<LocalTransform>())
    11.         {
    12.             trans.Translate(new Unity.Mathematics.float3(1, 0,0));
    13.         }
    14.     }
    15. }
     
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    Of course, because Translate returns new value which you should assign to LocalTransform back, have you checked method signature, and return value havent disturbed you? :) It's even explicitly mentioned in method remarks.
    upload_2023-4-7_10-10-3.png
     
  5. SlumberPenguin

    SlumberPenguin

    Joined:
    Sep 20, 2020
    Posts:
    25
    I searched for a day and still can't find a way to move objects. god
     
  6. Arnold_2013

    Arnold_2013

    Joined:
    Nov 24, 2013
    Posts:
    262
    I am not at my computer, but maybe this will already be enough to make it work.

    trans = trans.Translate(new Unity.Mathematics.float3(1, 0,0));
     
  7. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    You need to use RefRW otherwise you're just getting a read only copy of LocalTransform
    Code (CSharp):
    1.  
    2. foreach(var transRW in SystemAPI.Query<RefRW<LocalTransform>>())
    3. {
    4.     ref var trans = ref transRW.ValueRW;
    5.     trans = trans.Translate(new float3(1, 0,0));
    6.  
    7.     // Or
    8.     // trans.Position = trans.Position + new float3(1, 0, 0);
    9. }
    10.  
     
    Bazeragi and hughperkins like this.