Search Unity

[Solved] LocalToWorld seems to be updated every frame no matter what

Discussion in 'Entity Component System' started by YurySedyakin, Feb 26, 2020.

  1. YurySedyakin

    YurySedyakin

    Joined:
    Jul 25, 2018
    Posts:
    63
    I've tried this:

    Code (CSharp):
    1. public class ChangeDetectionSystem : JobComponentSystem
    2.     {
    3.         protected override JobHandle OnUpdate(JobHandle inputDeps)
    4.         {
    5.             return this.Entities
    6.                 .WithChangeFilter<LocalToParent>()
    7.                 .ForEach(
    8.                     (in Entity entity, in LocalToParent ltp) =>
    9.                     {
    10.                         UnityEngine.Debug.Log($"LocalToParent changed in {entity}");
    11.                     }
    12.                 )
    13.                 .Schedule(inputDeps);
    14.         }
    15.     }
    And for a child entity with the Translation component it detects change in LocalToParent every frame. I've looked through the source of TRSToLocalToParentSystem and it seems to me that it doesn't check DidChange. Interesting that TRSToLocalToWorldSystem and LocalToParentSystem both perform change checks. So my question is: did I miss something? Or is it by design? Or some considerations that I'm not aware of?
     
  2. YurySedyakin

    YurySedyakin

    Joined:
    Jul 25, 2018
    Posts:
    63
    Ok, I've tried a subscene with just one empty game object. When converted it produces just one entity with LocalToWorld and Translation. In this case LocalToWorld gets updated just two first frames then I think change detection comes into play and .WithChangeFilter<LocalToWorld>() stops picking up the entity. This means that TRSToLocalToWorldSystem definitely respects Translation (un)changed status.
     
  3. YurySedyakin

    YurySedyakin

    Joined:
    Jul 25, 2018
    Posts:
    63
    So does anybody know if it is working now as intended? I.e. should the LocalToParentSystem actually perform matrix calculation every frame, even when there's no change? I think it would be beneficial if this aspect was optimized. Not only would it reduce the amount of unnecessary calculations, but it would also allow other systems to only work when the positioning of an entity in the world has actually changed.
     
  4. YurySedyakin

    YurySedyakin

    Joined:
    Jul 25, 2018
    Posts:
    63
    If anyone is interested or not, I have checked Entities 0.7.0 and can confirm that this issue has been resolved. I.e. now LocalToWorld on children is NOT being updated every frame when there is no change. Thank you Unity Entities team.
     
    brunocoimbra and tertle like this.
  5. SebastianAaltonen

    SebastianAaltonen

    Unity Technologies

    Joined:
    Feb 21, 2020
    Posts:
    112
    Yes. I fixed that bug. The LocalToWorld system was updating all entities LocalToWorld every frame if they had a parent. Now it only updates LocalToWorld, if any parent above it has changed LocalToWorld. The check is at chunk granularity, so you might sometimes see extra updates. But on the other hand the check is practically free.