Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Kinematica: Demo - Null Exceptions when clicking character and hovering inspector

Discussion in 'Animation Previews' started by simonaaitor, Dec 8, 2020.

  1. simonaaitor

    simonaaitor

    Joined:
    Sep 8, 2020
    Posts:
    11
    Hi, just wanted to notify this bug, which also triggers when enabling/disabling an ability (related post last month). Something with the ledge object?

    It happens when clicking the character on the hierarchy, and then continuously when hovering the inspector with the character selected. Attaching image.

    Thanks, Aitor
     

    Attached Files:

  2. grahamsaulnier

    grahamsaulnier

    Unity Technologies

    Joined:
    Apr 10, 2018
    Posts:
    18
    Thanks for the info! Would you be able to report a bug using Unity's bug reporting window? Help->Report a bug..
     
    simonaaitor likes this.
  3. randomPoison

    randomPoison

    Joined:
    Apr 3, 2021
    Posts:
    5
    I noticed this issue as well, and did some digging to see what the cause was. It looks like the problem comes from
    SnapshotProviderEditor
    trying to calculate the snapshot size of
    ClimbingAbility.ledgeGeometry
    when not in play mode. Internally, the
    LedgeGeometry
    struct contains
    NativeArray
    field tracking the vertices of the ledge, but it is only initialized at runtime. So in the editor we get an error logged because trying to read the uninitialized
    NativeArray
    trips a safety check.

    As far as I can tell this isn't strictly a bug in Kinematica itself. For the demo, you can fix this updating
    LedgeGeometry.WriteToStream()
    (
    ClimbingAbility.Ledge.cs
    line 238) and adding a check against
    NativeArray.IsCreated
    so that it won't try to read the vertices array if it's not initialized:

    Code (CSharp):
    1. if (vertices.IsCreated)
    2. {
    3.     buffer.WriteNativeArray(vertices, Allocator.Persistent);
    4. }
    For any projects trying to use Kinematica, you'll only run into this error if you are doing something similar where you have a
    NativeArray
    inside of a type that you want to track via the snapshot inspector, and you can avoid the error with a similar approach.

    That said, I do wonder if the
    WriteExtensions.WriteNativeArray()
    that's being used in that function shouldn't be updated to check
    array.IsCreated
    in order to better handle this sort of case. I don't know know if the expectation is that
    WriteNativeArray()
    should only be called with an initialized array, and therefore it's on the caller to check
    IsCreated
    , but if not this could possibly be a place where Kinematica could be updated.

    @grahamsaulnier I can submit an official bug report if it still makes sense to do so, though given that Kinematica's development has been put on hold for the duration of 2021 I imagine it doesn't matter much at this point. If nothing else, I figure posting this information might save a Kinematica dev an hour of debugging when they do eventually return to it :D