Search Unity

Dependency errors

Discussion in 'Entity Component System' started by Squib, Nov 30, 2018.

  1. Squib

    Squib

    Joined:
    Nov 6, 2018
    Posts:
    2
    I am in the process of converting my game into using data-oriented design. I am using a central NativeArray of structs to hold my data instead of engaging with the ECS. My systems are JobComponentSystems, and the problem I'm currently having is that I am getting scheduling and dependency errors when trying to use the same NativeArray over multiple systems, and even when just using 1 system over multiple frames.

    I don't seem to be getting these errors when injecting a ComponentDataArray into the jobs. I'm not sure where to go from here to begin to fix these problems. I would like to keep everything in a tightly-packed array (because the order of everything is important) while still getting the benefits of using jobs.
     
  2. SubPixelPerfect

    SubPixelPerfect

    Joined:
    Oct 14, 2015
    Posts:
    224
    I suggest read more about race conditions and multithreading in general, to get understanding what causing this errors.

    you can't read and write the same data at the same time, and you can't write the same data from a few treads at the same time.
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    One of the primary functions of ECS is that it handles dependency management for you. If you are just going to use centralize data you need to manage all of these, potentially in the hundreds of dependencies yourself every frame.
     
  4. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I have one such "baked" native array of 5 elements since being able to use int to index to the correct element is important to performance my game. But fixed ordering is generally a weakness by design of ECS.

    JobHandle does not seems to understand NativeArray in the job as dependency so JCS's auto .Complete missed completing the job which could have be writing to this NA at the moment.

    What I do is that the JCS writing to this NA needs to schedule and complete its job immediately. Then all user of this NA put an attribute [UpdateAfter] that system baking the NA to ensure they get a baked value every frame, then they can use the array as they want with [ReadOnly] on it. (I [Inject] the baking system and just pull out the array from its public property then throw it in to a job, or use World.GetExistingManager if you don't want to use the to be deprecated inject)
     
    Deleted User likes this.