Not null variable (according to debugger) falls in == null check

This is in a netcode for entities project, the code is called during baking. This are the components related to the issue:

  1. A serialized list of data consisting of AnimationClip and float value.
  2. Clip is set in editor.
  3. A baker that gets a reference to the clip
  4. In the same baker Unity Editor class is used to get the curve from the clip
  5. And that method is throwing the exeption because clip is treated as null, although debugger shows that it is not, it is a get only property and there are no more usages of that clip.

What I’ve tried:

  • recompiling code several times, restarting unity
  • delete authoring components and add them again, delete the clip from the list and set it again
  • make duplicates of clip and reference them
  • change clip’s animation type to legacy/humanoid/generic
  • check if == operator is overloaded for animation clip (it is not)
  • use lock object for this baker
  • update editor to latest 6.0 LTS version

Rider is configured to debug mode

When debugging that line (clip == null) I can’t go inside the operator== overload method like in other checks. When I step over I immediately go to the catch block, if I step into I get to the line that throws, as shown above.

Of course, that did not help. I would appreciate help, thanks in advance

AnimationClip inherits from UnityEngine.Motion which itself inherits from UnityEngine.Object, which has the overloaded lifetime operators. It seems likely that the Animation Clip is destroyed, but I don’t know why it would be. It’s also weird that when debugging Rider shows (bool) false at the comparison.

Try to find the earliest place where clip == null is true. Is this the case at the start of the Bake method? If so, about the only thing I can think of right now is to see if using a backing field may fix the issue (unlikely but you never know).

If clip is not null at the start of Bake the clip gets destroyed at some point during the Bake method. In that case step through the code to see where it happens.

PS: please post code as text enclosed in code tags. Screenshots cannot be quoted, edited, searched, and sometimes are hard to read (here, each shot has a different text size).

Sometimes where are scenarios when people use β€œis null” comparison, instead of ==, but this is not the case here, == should work just fine. And yes, the strangest thing is that in debugger variable is neither null nor missing reference exception.

Thats the interesting part, its never null in other places, even if I check right before the AnimationUtility line. And its not null when debugging it, which is also never the case normally. (question style suggestion noted)

If something odd like this happens, I tend to restart editor and IDE (if not restarting the system) just to be sure it’s not some sort of lingering issue.

So the problem was caused by not having set curves in animation clip, however, I still don’t understand the issue there GetValueOrDefault returns default EditorCurveBinding without throwing, and then code executes according to the screenshots above, with falling into false if statement.

1 Like

Hi, denissmirnovdeveloper. It would be great to take a closer look into this. Could you report a bug via the Bug Reporter (β€œHelp β†’ Report a Bug…” in the Unity Editor)? Make sure to attach your project so it would be easier to reproduce this. Cheers.

Hello, just finished it

1 Like