Search Unity

Job System/ECS using Tiles and Tilemaps

Discussion in 'C# Job System' started by skylinx, May 11, 2019.

  1. skylinx

    skylinx

    Joined:
    Nov 1, 2012
    Posts:
    3
    Hello! I've just recently started utilizing the Job System/ECS for my large scale simulations. It's truly a great addition to the engine once you get used to it. I am posting here today because I'm desperate for an answer to the following question:

    Can you convert Unity Tiles/Tilemaps in to native structures for use with the Job system?

    To give you some background, I've previously created a massive 2D terrain generation system that uses cubic noise and Tilemaps to achieve its goals. The code I wrote is quick and works well but the main thread of the program suffers while generating. I'm using a coroutine but that does not solve the issue completely. You're still at mercy of that single thread. Knowing that Unity API is not thread safe I've decided to use the Job System to perform my generation.

    The noise generation works beautifully because I can just convert the 2D array of floats to a flattened NativeArray. Works nicely. However, noise generation was never really the issue. It's quite fast even on the main thread. Filling the tilemap is what puts strain on the main thread, and I cannot for the life of me figure out how to put that workload on a scheduled job.

    Native structures cannot contain reference types, so I cannot use Tile or Tilemap within my job execution.

    I also do not want to reference the Tiles or Tilemaps statically within my Job (this is a bad idea don't do it)

    TLDR:

    Should I create my own tilemap rendering system which can be easily broken down to structs for use with the Job?

    Is it possible to somehow use Tiles and Tilemaps with the Job system?

    Does anyone have any ideas on how I could do this? Thanks in advance.
     
    tonytopper likes this.
  2. The-Exceptional-Bruce

    The-Exceptional-Bruce

    Joined:
    May 10, 2015
    Posts:
    29
    I know you asked this a while back, but maybe it help you see where Unity ECS is going.

    https://forum.unity.com/threads/project-tiny-c-preview-0-15-3-available.688969/

    Except from link.
    Where is the Physics module (Physics2D)?

    Project Tiny Preview 0.15.3 does not include Physics2D. We are in the process of bringing an improved DOTS 2D Physics module. You can still use HitBox2D for lightweight intersection and overlap checking module that does not require physics.

    Where is the Tilemap2D Module?
    Project Tiny Preview 0.15.3 does not include the Tilemap2D module. We are in the process of bringing improved 2D modules, designed for DOTS mode.