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

Bug Systems inside a namespace have no effect on physics when their name is... somehow wrong?

Discussion in 'Entity Component System' started by janhohenheim, Sep 6, 2020.

  1. janhohenheim

    janhohenheim

    Joined:
    Feb 10, 2020
    Posts:
    1
    Steps to reproduce:
    - Install Unity 2020.2.0a21
    - Create a new Unity DOTS project named "PlanetaryPhysics" with the following versions:
    - "com.unity.entities": "0.14.0-preview.18"
    - "com.unity.physics": "0.4.1-preview"
    - Create a physics object (remove default collider, convert to entity, add physics shape, add physics body)
    - Create a directory named "Aaaaaa"
    - Create a system inside the new directory named "PlanetaryGravitationalForceSystem"
    - Add the following code to the System:
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Transforms;
    3.  
    4. namespace Aaaaaa
    5. {
    6.     public class PlanetaryGravitationalForceSystem: SystemBase
    7.     {
    8.         protected override void OnUpdate()
    9.         {
    10.             Entities
    11.                 .ForEach((ref Translation translation) =>
    12.                 {
    13.                     translation.Value += 100;
    14.                 })
    15.                 .ScheduleParallel();
    16.         }
    17.     }
    18. }
    Expected behavior: The physics objects should fly across the screen
    Actual behavior: Nothing
    Steps to fix: Rename the System to anything else or move it out of the namespace

    The error seems to not stem from the length of the system name, since the code works fine when naming the system "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa". I don't know if there are some weird keywords I've hit or if the fact that my system starts with the same word as my project is relevant.
     
  2. Scorr

    Scorr

    Joined:
    Jul 2, 2013
    Posts:
    73
    Sounds like you might be hitting an issue with ordering, where changing the namespace/class name would implicitly change the order since none is specified. If you want to change physics you either want to order your system to be
    - before BuildPhysicsWorld (before physics step)
    or
    - after ExportPhysicsWorld (after physics step)

    If it happens in between these, physics would be running on an outdated version of the Translation and overwriting it.
     
    florianhanke likes this.
  3. s_schoener

    s_schoener

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    81
    Thanks for reporting this. It's an unfortunate side-effect of the way how systems are sorted, but there is no easy architectural solution. If you have any dependencies, please follow Scorr's advice and make them explicit by using UpdateAfter / UpdateBefore / UpdateInGroup.