Search Unity

ComponentDataArray Deprecated?

Discussion in 'Entity Component System' started by nttLIVE, Jan 23, 2019.

  1. nttLIVE

    nttLIVE

    Joined:
    Sep 13, 2018
    Posts:
    80
    With ComponentDataArray being deprecated, is the proper way of getting components only through Chunks iteration and IJobProcessComponentData now?

    EDIT: I confused ComponentArray with ComponentDataArray.
     
    Last edited: Jan 23, 2019
  2. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    ComponentArray: Used for classes (hybrid) E.g. you want to access a Monobehaviour scripts or legacy components like Rigidbody or Animator

    ComponentDataArray: For all struct IComponentData (Pure)
     
  3. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    There is a new ForEach syntax provided as ComponentSystem's protected method in the lastest version. It uses chunk interation inside. Maybe you should try using it.
     
  4. nttLIVE

    nttLIVE

    Joined:
    Sep 13, 2018
    Posts:
    80
    Yes I'm aware, the question was edited properly.

    Is there a reference to this new syntax I could read on? I'm not sure I even see it on the change log. This sounds amazing.
     
  5. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I wonder if they are not mentioning the ForEach because it is not usable yet? I haven't upgrade the version, but I see ForEachLambdaTests.cs that demonstrate some use. Basically ForEach( (ref T comp) => ____ ); then you could modify comp in the same fashion as IJobProcessComponentData but this is a non-job version.

    Seems like each possible lambda combination that ForEach can handle was machine generated and appended to ComponentSystem via partial C# syntax. Currently there is a 3000 line file handling combinations of delegates of ref CDA/no ref CDA (for read only access)/SCD/dynamic buffer/Entity. The generator tool is also included so you could get more combinations I suppose.
     
    nttLIVE likes this.
  6. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    with ForEach syntax is so easy to create garbage:
    Code (CSharp):
    1. void OnUpdate() {
    2.     var dt = Time.deltaTime;
    3.     ForEach((ref Position p) => p.Value += dt*float3(1,2,3)); // <- I am capturing a local!!!
    4. }
     
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    May be that why is in experimental yet? What to do, to prevent garbage in such case?
     
  8. elcionap

    elcionap

    Joined:
    Jan 11, 2016
    Posts:
    138
    IIRC when you use data from stack outside the anonymous function/lamba a class is generated to hold the data. So you shouldn't declare anything that way. Use a field in the system instead.
    Code (CSharp):
    1. float m_DeltaTime;
    2.  
    3. protected override void OnUpdate() {
    4.     m_DeltaTime = Time.deltaTime;
    5.  
    6.     ForEach((...)=> {
    7.         ...m_DeltaTime
    8.     }
    9. }
    []'s
     
    Antypodish likes this.
  9. Jay-Pavlina

    Jay-Pavlina

    Joined:
    Feb 19, 2012
    Posts:
    195
    Make it static?

    Edit: An instance field would work too. That should just be a single allocation.