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

Bug "...uses unsafe Pointers which is not allowed..." Despite using [NativeDisableUnsafePtrRestriction]

Discussion in 'Entity Component System' started by MatanYamin, Oct 6, 2022.

  1. MatanYamin

    MatanYamin

    Joined:
    Feb 2, 2022
    Posts:
    109
    Hey everyone.

    Despite using "[NativeDisableUnsafePtrRestriction]" I still have an error.

    I am trying to do something pretty simple, but I still keep getting the same error when running my game.

    All I want to do is simply pass my "TransformAccessArray" from the main thread to the Job system "IJobParallelForTransform".

    At first, I found out I need to add "[NativeDisableUnsafePtrRestriction]" but after adding it, I still keep getting the same error:

    "...m_TransformArray uses unsafe Pointers which is not allowed. Unsafe Pointers can lead to crashes and no safety against race conditions can be provided.
    If you really need to use unsafe pointers, you can disable this check using [NativeDisableUnsafePtrRestriction]."


    Also adding "[ReadOnly]" didn't help. All I need is to read a certain data from a certain transform.
    This is the line inside the IJobParallelForTransform:
    Code (CSharp):
    1. [NativeDisableUnsafePtrRestriction] public TransformAccessArray transformArray;
    Please, can someone give me a hand on this?
     
    Last edited: Oct 6, 2022
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Hi, key here is that TransformAccessArray is passed via Execute parameter automatically as TransformAccess.
    So you don't need / can't pass it manually like that.

    See example here:
    https://docs.unity3d.com/ScriptReference/Jobs.IJobParallelForTransform.html
     
  3. Deleted User

    Deleted User

    Guest

    I'm facing this same issue, but I'm wanting to dispose of the transform access array in a job (so that it's automatically disposed). Any ideas?