NullReference from Collision2D other

Hello,

I’m getting a null reference where Stephen is not, but I’m confident my code and slimes setup are identical to his at this point in the lecture. I know it’s detecting the slime and EnemyAI class since it’s still updating health in the console, but I’m not getting knocked back or a flash.



playerknockbackerror

Thank you in advance.

Line 33 is

knockback.GetKnockedBack(other.gameObject.transform, knockBackThrustAmount);

Since other is a collider, it must be valid and have a gameObject (and therefore a transform), so this cannot be the source of the error.

The only thing left that can be null is the knockback component itselt.
Make sure that your Knockback component is properly assigned either with a GetComponent in Awake or if it’s a serializeField, make sure it’s assigned in the inspector.

1 Like

Thanks Brian!

I did not have the Knockback class assigned to the Player. I forgot to add it, and was just stuck on other being the object reference it was looking for. Thanks for the help!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms