Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug `TransformAccessArray.Add(int)` behave different than `TransformAccessArray.Add(Transform)`

Discussion in 'C# Job System' started by Enderlook, Apr 23, 2024.

  1. Enderlook

    Enderlook

    Joined:
    Dec 4, 2018
    Posts:
    56
    I noticed that `TransformAccessArray.Add(int)` doesn't behave in the same way as `TransformAccessArray.Add(Transform).`
    When you add `0`, the first overload ignores it and its length doesn't increase. But when you add `null`, the second overload does increases its length.
    This is breaking my code. I tried to replace the usage of `.Add(Transform)` with `.Add(int)` to use the Burst compiler, but now I realise the behaviour is not the same. If the integer overload doesn't accept the "null" (0) transforms, I'm forced to have additional native arrays and jobs to sync any result that I get in whatever job the transformaccessarray is used as it doesn't match the same sequence of elements that I have.

    I guess this is a bug, since the documentation doesn't specify that `.Add(int)` ignores 0.

    I reported the bug a minute ago. I make this thread to see if more users struggle with this like me.
     
    gshape likes this.
  2. Enderlook

    Enderlook

    Joined:
    Dec 4, 2018
    Posts:
    56