Search Unity

Upcoming API changes in 0.27

Discussion in 'Entity Component System' started by v_vuk, Apr 5, 2019.

  1. scobi

    scobi

    Unity Technologies

    Joined:
    May 14, 2014
    Posts:
    32
    It's not something we've started implementing just yet (still in design phase), so I can't put a timeline on it currently.
     
    optimise and GilCat like this.
  2. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    Is there a replacement for [RequireSubtractiveComponent()]? It seems to be missing/gone in .30
     
  3. scobi

    scobi

    Unity Technologies

    Joined:
    May 14, 2014
    Posts:
    32
    From ReleaseNotes.md:

    * Subtractive renamed to Exclude
    * `[RequireSubtractiveComponent]` renamed to `[ExcludeComponent]`
     
    FrankvHoof likes this.
  4. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    After Updating from 2018 to 2019 (and from .24-timestamp to .30), I'm now also unable to use the Inspector.

    It seems like the Editor/Inspector is trying to load PositionProxy, but can't. This prevents me from viewing any & all GameObjects in the Inspector (including non-ecs-objects)
    Console logs:
    Code (CSharp):
    1. TypeLoadException: Could not load type Unity.Transforms.PositionProxy, Unity.Transforms.Hybrid, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null while decoding custom attribute: (null)
    2. System.MonoCustomAttrs.GetCustomAttributesBase (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inheritedOnly) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0)
    3. System.MonoCustomAttrs.GetCustomAttributes (System.Reflection.ICustomAttributeProvider obj, System.Type attributeType, System.Boolean inherit) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0)
    4. System.RuntimeType.GetCustomAttributes (System.Type attributeType, System.Boolean inherit) (at <1f0c1ef1ad524c38bbc5536809c46b48>:0)
    5. UnityEditor.CustomEditorAttributes.Rebuild () (at C:/buildslave/unity/build/Editor/Mono/CustomEditorAttributes.cs:124)
    6. UnityEditor.CustomEditorAttributes.FindCustomEditorTypeByType (System.Type type, System.Boolean multiEdit) (at C:/buildslave/unity/build/Editor/Mono/CustomEditorAttributes.cs:34)
    7. UnityEditor.CustomEditorAttributes.FindCustomEditorType (UnityEngine.Object o, System.Boolean multiEdit) (at C:/buildslave/unity/build/Editor/Mono/CustomEditorAttributes.cs:26)
    8. UnityEditor.InspectorWindow.IsMultiEditingSupported (UnityEditor.Editor editor, UnityEngine.Object target) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1495)
    9. UnityEditor.UIElements.EditorElement.HeaderOnGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/EditorElement.cs:187)
    10. UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:278)
    11. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    Edit: Nvm... After doing a 'Reimport All', the issue went away. Now the only error I'm getting is the errors in Unity.Entities.PerformanceTests (which I can just delete, as they're only tests)
     
    Last edited: Apr 23, 2019
  5. rsodre

    rsodre

    Joined:
    May 9, 2012
    Posts:
    229
    I hope at least the errors generated by generic components could be suppressed meanwhile.
    I have errors on my console every single run.
     
  6. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    I used to go in TypeManager.cs and comment line 472 just to get rid of the error spam. Unfortunately one must do this every single time the editor is opened.
    I've done some builds where i use generics in IComponentData and all seems to run as expected so i wonder what is being broken by this?
    @scobi @v_vuk Will a build where this error happens crash at some point or work incorrectly right now?
    Anyway i have replaced my generic usage with concrete component data for now.
    Also i would like to congratulate Unity Team for the great effort they have put in moving the whole DOTS forward.
     
    JesOb and FROS7 like this.
  7. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    The error is quite annoying, also I want to try using Chunk, so I use another way to implement TimerSystem without generic. The goal is to keep multiple Timer in one entity therefore I choose DynamicBuffer. Finally I get something like this.

    Code (CSharp):
    1. using Unity.Burst;
    2. using Unity.Collections;
    3. using Unity.Entities;
    4. using Unity.Jobs;
    5. using Unity.Mathematics;
    6. using UnityEngine;
    7.  
    8. public struct Timer : IBufferElementData
    9. {
    10.     public float elapsedTime;
    11.     public float duration;
    12.     public bool running;
    13.     public bool started;
    14.  
    15.     public bool Started
    16.     {
    17.         set { started = value; }
    18.         get { return started; }
    19.     }
    20.     public float Duration
    21.     {
    22.         get { return duration; }
    23.         set
    24.         {
    25.             if ( value > 0 && !Running )
    26.             {
    27.                 duration = value;              
    28.             }
    29.         }
    30.     }
    31.     public bool Finished
    32.     {
    33.         get { return Started && !Running; }
    34.     }
    35.  
    36.     public bool Running
    37.     {
    38.         get { return running; }
    39.         set { running = value; }
    40.     }
    41.  
    42.     public void Run()
    43.     {
    44.         elapsedTime = 0;
    45.         started = true;
    46.         running = true;
    47.     }
    48.     public void Stop()
    49.     {
    50.         elapsedTime = 0;
    51.         started = false;
    52.         running = false;
    53.     }
    54. }
    55.  
    56. // foreach buffer
    57.  
    58. // update each element in it.
    59. public class TimerSystem : JobComponentSystem
    60. {
    61.     private EntityQuery m_TimerGroup;
    62.  
    63.     public struct TimerUpdateJob : IJob
    64.     {
    65.         [DeallocateOnJobCompletion]
    66.         public NativeArray<ArchetypeChunk> chunks;
    67.         public ArchetypeChunkBufferType<Timer> timersType;
    68.         public float deltaTime;
    69.         public void Execute()
    70.         {
    71.             // how many chunks?
    72.             for (int i = 0; i < chunks.Length; i++)
    73.             {
    74.                 var chunk = chunks[i];
    75.                 var timersAccessor = chunk.GetBufferAccessor<Timer>(timersType);
    76.  
    77.                 // I think chunk.Count == timersAccessor.Length == naArray<Archetype>.Length
    78.                 // how many entities in this chunk?
    79.                 for (int j = 0; j < chunk.Count; j++)
    80.                 {
    81.                     var timers = timersAccessor[j];
    82.                     // how many timer in Timers Array?
    83.                     for (int k = 0; k < timers.Length; k++)
    84.                     {
    85.                         var copyTimer = timers[k];
    86.                         Debug.Log("not running");
    87.                         if (copyTimer.Running)
    88.                         {
    89.                             Debug.Log("running");
    90.                             timers[k] = new Timer
    91.                             {
    92.                                 started = timers[k].started,
    93.                                 running = timers[k].running,
    94.                                 elapsedTime = timers[k].elapsedTime + deltaTime,
    95.                                 duration = timers[k].duration,
    96.                             };
    97.                             if (copyTimer.elapsedTime > copyTimer.Duration)
    98.                             {
    99.                                 timers[k] = new Timer
    100.                                 {
    101.                                     running = false,
    102.                                     started = true,
    103.                                 };
    104.                             }
    105.                         }
    106.                     }                  
    107.                 }
    108.             }          
    109.         }
    110.     }
    111.  
    112.     protected override JobHandle OnUpdate(JobHandle inputDeps)
    113.     {
    114.         var chunks = m_TimerGroup.CreateArchetypeChunkArray(Allocator.TempJob);
    115.  
    116.         return new TimerUpdateJob{
    117.             chunks = chunks,
    118.             timersType = GetArchetypeChunkBufferType<Timer>(false),
    119.             deltaTime = Time.deltaTime,
    120.         }.Schedule(inputDeps);
    121.     }
    122.     protected override void OnCreate()
    123.     {
    124.         m_TimerGroup = GetEntityQuery(new EntityQueryDesc{
    125.             All = new ComponentType[] {
    126.                 typeof(Timer),
    127.             }
    128.         });
    129.     }
    130. }
    131.  
    It's has little readability compare to @Spy-Shifty 's solution, also hard to debug and extend.
    Code (CSharp):
    1.     struct Timer<T> : IComponentData {
    2.         public float elapsedTime;
    3.         private float duration;
    4.         private bool running;
    5.         private bool started;
    6.         //...
    7.     }
    8.     public class TimerUpdateGroup : ComponentSystemGroup { }
    9.     [UpdateInGroup(typeof(TimerUpdateGroup))]
    10.     public abstract class TimerSystem<T> : JobComponentSystem  where T: struct {
    11.        struct TimerUpdateJob : IJobProcessComponentData<Timer<T>> {
    12.             public void Execute(ref Timer<T> c0) {
    13.                 // do timer update...
    14.             }
    15.         }
    16.         protected override JobHandle OnUpdate(JobHandle inputDeps) {
    17.             return new TimerUpdateJob().Schedule(this, inputDeps);
    18.         }
    19.     }
    20.     //somewhere...
    21.     EntityManager.AddComponentData(entity, new Timer<MySpecificTimer>());
    22.     public class MySpecificTimerSystem : TimerSystem<MySpecificTimer> { }
    I know I'm not a good coder as him though, just want to say generic is a good thing:D. BTW, Any suggestion is welcome.
     
  8. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    Why did you change your job from IJobProcessComponentData<> to IJob?
    You should have TimerUpdateJob : IJobForEach<Timer>
     
  9. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    177
    of course I want to do that, but IJobForEach can only accept IComponentData as parameter.
     
  10. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    Sorry i missed that Timer was an IBufferElementData.
    Then you must use IJobChunk and pass and BufferFromEntity<Timer> to it.
     
    Last edited: Apr 24, 2019
  11. scobi

    scobi

    Unity Technologies

    Joined:
    May 14, 2014
    Posts:
    32
    Yeah I agree it's annoying, I'll work on it.
     
    eterlan, rsodre and FROS7 like this.