Search Unity

SPH ECS to unity 2019.2 need help

Discussion in 'Entity Component System' started by cbutton, Aug 6, 2019.

  1. cbutton

    cbutton

    Joined:
    Nov 6, 2016
    Posts:
    2
    Hello all, I am trying to implement a fluid system for an application using ECS.

    Here is the source code I am trying to convert to unity 2019.2: https://github.com/leonardo-montes/...PH/blob/master/Assets/Job System/SPHSystem.cs

    My problem areas:
    Code (CSharp):
    1.  // Cache the data
    2.             NativeArray<Translation> translations = SPHCharacterGroup.CopyFromComponentDataArray<Translation>(null, out inputDeps);
    3.             NativeArray<SPHVelocity> velocities = SPHCharacterGroup.CopyFromComponentDataArray<SPHVelocity>(null, out inputDeps);
    In the above code I am using the argument null as a placeholder because I can't figure out what to use there, the original (containing deprecated code) looks like this:
    Code (CSharp):
    1. // Cache the data
    2.             ComponentDataArray<Position> positions = SPHCharacterGroup.GetComponentDataArray<Position>();
    3.             ComponentDataArray<SPHVelocity> velocities = SPHCharacterGroup.GetComponentDataArray<SPHVelocity>();

    And my final errors are here, on particle count:
    Code (CSharp):
    1.             // Copy the component data to native arrays
    2.             ComponentDataFromEntity<Translation> particlesTranslationJob = new ComponentDataFromEntity<Translation>();
    3.             JobHandle particlesTranslationJobHandle = particlesTranslationJob.Schedule(particleCount, 64, inputDeps);
    4.  
    5.             ComponentDataFromEntity<SPHVelocity> particlesVelocityJob = new ComponentDataFromEntity<SPHVelocity>();
    6.             JobHandle particlesVelocityJobHandle = particlesVelocityJob.Schedule(particleCount, 64, inputDeps);
    7.  
    8.             ComponentDataFromEntity<SPHCollider> copyCollidersJob = new ComponentDataFromEntity<SPHCollider>();
    9.             JobHandle copyCollidersJobHandle = copyCollidersJob.Schedule(colliderCount, 64, inputDeps);
    The original looks like this:
    Code (CSharp):
    1.             // Copy the component data to native arrays
    2.             CopyComponentData<Position> particlesPositionJob = new CopyComponentData<Position> { Source = positions, Results = particlesPosition };
    3.             JobHandle particlesPositionJobHandle = particlesPositionJob.Schedule(particleCount, 64, inputDeps);
    4.  
    5.             CopyComponentData<SPHVelocity> particlesVelocityJob = new CopyComponentData<SPHVelocity> { Source = velocities, Results = particlesVelocity };
    6.             JobHandle particlesVelocityJobHandle = particlesVelocityJob.Schedule(particleCount, 64, inputDeps);
    the error for these is: cannot convert from 'int' to 'Unity.Collections.NativeMultiHashMaps<int, int>'

    Would appreciate any help and explanation!
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    Code (CSharp):
    1.  // Cache the data
    2.             NativeArray<Translation> translations = SPHCharacterGroup.ToComponentDataArray<Translation>(Allocator.TempJob, out transDeps);
    3.             NativeArray<SPHVelocity> velocities = SPHCharacterGroup.ToComponentDataArray<SPHVelocity>(Allocator.TempJob, out velsDeps);
    4.             inputDeps = JobHandle.CombineDependencies(inputDeps, transDeps, velsDeps);
    ToComponentDataArray copies the components to NativeArrays. CopyFromComponentDataArray writes the NativeArray values back to the entities at the same indices that are assigned in ToComponentDataArray.

    Use GetComponentDataFromEntity to get a ComponentDataFromEntity if you need random access based on an Entity input.
     
    cbutton likes this.
  3. cbutton

    cbutton

    Joined:
    Nov 6, 2016
    Posts:
    2
    Thank you for your answer, if you don't mind could you please explain your addition of transdeps and velsdeps please? I am unsure as to what their purpose is. Right now I've had to add them as global private JobHandles.

    Also I still have the error: Assets\Scripts\ECS\SPHSystem.cs(408,74): error CS1503: Argument 2: cannot convert from 'int' to 'Unity.Collections.NativeMultiHashMap<int, int>'

    So far I have not found a solution to this.
     
    Last edited: Aug 7, 2019
  4. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
    .ToCDA() uses a job to create the native array, if you omit the job handle, it will call .complete & create a sync point - if you supply a job handle, it will chain the dependencies and complete the jobs as required by their dependencies
     
  5. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,271
    Code? An error means very little if we can't look at the exact line the error message tells us to look at as well as the preceding context.