Search Unity

Resolved Physics 0.50 - CalculateDistance with custom collector error

Discussion in 'Physics for ECS' started by DevViktoria, Mar 22, 2022.

  1. DevViktoria

    DevViktoria

    Joined:
    Apr 6, 2021
    Posts:
    94
    Hi,
    with the Unity Physics 0.17 (+ Collections 0.15.0 preview 21) the following custom collector code has worked:
    Code (CSharp):
    1. public struct OtherNonTriggerHitsCollector<T> : ICollector<T> where T : struct, IQueryResult
    2. {
    3. public NativeList<T> AllHits;
    4. .....
    5. public OtherNonTriggerHitsCollector(int rigidBodyIndex, float maxFraction, ref NativeList<T> allHits)
    6. {
    7. ....
    8. }
    9. }
    Similar to the custom collectors here in the Physics Samples:
    https://github.com/Unity-Technologi...oller/Scripts/CharacterControllerUtilities.cs

    But with the Physics 0.50 and the Collections 1.2.3-pre.1 this gives me the error:
    Code (CSharp):
    1. The type 'T' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'T' in the generic type or method 'NativeList<T>'
    Is there any solution to this issue?
    AFAIK the samples hasn't been updated yet and I need this for my own things.
     
  2. papopov

    papopov

    Joined:
    Jun 29, 2020
    Posts:
    32
    Try using unmanaged constraint:
    public struct OtherNonTriggerHitsCollector<T> : ICollector<T> where T : unmanaged, IQueryResult
    {...}
     
    DevViktoria likes this.
  3. DevViktoria

    DevViktoria

    Joined:
    Apr 6, 2021
    Posts:
    94
    It worked thank you very much :) And can you tell me if this was documented somewhere and I missed it?