Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Increment value in NativeArray while job is running

Discussion in 'Entity Component System' started by crowmaster, Sep 15, 2023.

  1. crowmaster

    crowmaster

    Joined:
    Jul 6, 2012
    Posts:
    73
    I want to atomically increment the value of a specific NativeArray from outside the job, while job is actually running. It is currently giving me InvalidOperationException as i try doing it. I do not want to call Job.Complete() cause it will hit the performance significantly. Any ways?
     
  2. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    You have to include this NativeArray into your job.
     
  3. crowmaster

    crowmaster

    Joined:
    Jul 6, 2012
    Posts:
    73
    Thats not exactly what i want. I want to use somthing like Interlocked to increase the value of NativeArray while the job is running. I do not want to sync threads for that.
     
  4. vectorized-runner

    vectorized-runner

    Joined:
    Jan 22, 2018
    Posts:
    383
    You can always bypass safety if you just get the pointer and add the
    NativeDisableUnsafePtrRestriction attribute