NullReferenceException when using other animations

  • Hi
    I'm am having a bit of trouble getting animations to work correctly on the prefabs, I've added all the components and they do spawn and move in the game, yet no animation. I get the error:

    NullReferenceException: GetRef
    Properties+<OnSpawn>c__Iterator6.MoveNext () (at Assets/imported/3D Tower Defense Starter Kit/Scripts/Enemy/Properties.cs:85)

    I've tried with two different bought assets, and I've thoroughly checked that my prefabs have the same settings as the standard ones, so I'm probably missing something else.

    Any ideas? :)

  • Hi Doomberg,

    welcome to the forum!

    Line 85 in Properties.cs refers to:
    anim[].time = Random.Range(0f, anim[].length);

    Since that line is only being called if walkAnim is not null, the only possible cause for the NullReferenceException is the anim variable. Did you attach an (old-school) Animation component to your prefab and dragged in your animations, as seen on the sample ones (peasant, knight, etc.)?

  • Thanks for the welcome and your reply :)

    Yes, I've added the animation component to a child object, in the same manner as the standard assets.
    I also tried adding it to the parent, but got the same result. When I use your animations on the models, I don't get the NullReferenceException, could the fault be with the animations even though I've tried two different assets?

    Here's a picture of the animation component.

  • Thanks for the screenshot. What I can see immediately is that the layer should be "Enemies", not "WorldLimit".

    I guess this doesn't cause the exception though. Could you please send me your model+prefab via email, so I can try to set it up for you?

  • Alright, I'll change the layer :) And yes, that'd be great. I'll just upload it. Can I send it somewhere private, just so I don't share it publicly?

  • My email address is on the last page in the documentation pdf, or on the bottom of our website.

  • Alright, I've sent you an email :)

  • Solved by setting the model rig & animation clips to legacy.

Log in to reply