I am using a script to make an Animated Sprite class (found here: [https://bit.ly/3cIZX68]) and it is giving me the error saying that my AnimatedSprite anim was null, even though it was defined directly before. Here is the snippet of code.
'if (isMoving)
{
anim = animations[1];
anim.Update(gameTime);
}
else
{
anim = animations[0];
anim.Update(gameTime); //error is on this line saying anim is null
}`
The code you’re posting is too incomplete for me (or others) to get an accurate picture of what’s going on. From what you’ve posted, I can only offer the following…
In your first post, you’re referencing the animations array directly. In your second post, you’re showing that player.animations is initialized to a value. I can make a lot of assumptions about how you’re writing your code, but sticking just to what’s shown, there’s no evidence that “animations” and “player.animations” are referring to the same array.
It might be a good idea to throw a few breakpoints in your initializations, and where the actual data is used. Are they the same object?