Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Problems, I faced while using job system in my game

Discussion in 'C# Job System' started by Rewaken, Feb 20, 2019.

  1. Rewaken

    Rewaken

    Joined:
    Mar 24, 2015
    Posts:
    126
    Hello, first I want to thank unity for jobs/ECS without this system I can't even imagine making my game. I want to say that I am not that experienced developer and following issues may be a simple fix but it consumes too much of my time also I understand that it is not production ready yet still in beta. My native language is not English but I will still try to simplify everything so it will be easy for devs to understand the problem. I will start by explaining my game and how I am using the job system then I will list the problems I faced while developing the game.
    I am making RTS/RPG game for RTS part, I am using the job system. Previously when I was not using jobs I need to micro-optimize everything as I want to simulate large battle 20k-30k soldiers like even using Equality checks(==) proving costly. After moving to the job system I removed all game objects and move all logic in structs. I am using my own animator and pathfinding solution basically I am baking animation with shader and drawing them using DrawInstancedIndirect method.
    Every calculation(entities position, rotation, Animation State, AI behaviour) is done in parallel jobs. My project is over 20gbs and takes too much time to load(15 minutes).
    1)As mentioned above I am calculating everything in a parallel job, I made some changes in my code and while running game in the editor it just stuck no error anything the only option was to force close via task manager, after a few attempts and disabling burst jobs finally error was shown You cant use Random.Range inside jobs due to race condition after changing it with Unity.Mathematics.Random it finally works, but It will be really helpful if the bug was captured while using burst rather then crashing unity also closing and opening project, again and again, wastes too much time.
    2) (Not really sure if related to burst)Same thing no error log unity crash on its own even editor log file didn't help much even after updating to latest version same things happened but at least I got the reason for the crash via editor.log
    1. Unity.exe caused an Access Violation (0xc0000005)
    after searching online I found forum thread https://forum.unity.com/threads/unity-2018-3-0b3-crash-by-instancing-rendering-code.559726/ where unity, where unity dev mention that issue was resolved and backported but I was still getting an error after carefully examined each and every line of code I found the issue. In my game when a unit kills an enemy unit, it searches the next enemy unit to attack from the enemy group. following is code.

    Code (CSharp):
    1.  int min = MinMaxx[UnitMainId[AllTarget[i]] * 2];
    2. int max = MinMaxx[UnitMainId[AllTarget[i]] * 2 + 1];
    3. //Minmaxx is array which hold info for all units and with min and max I am getting particular no of starting and ending of enemy unit group in MinMaxx array.
    4.  
    5.  
    6.  


    So Minmaxx array range was 100 and UnitMainId[AllTarget] was more than that fixing that solves my issue but still whenever such condition comes unity crash with memory access violation error.
     
    MostHated likes this.