Slime NullReferenceException

I notice that if there is a slime and i walk near it it throws a NullReferenceException.

NullReferenceException: Object reference not set to an instance of an object
EnemyAI.Attacking () (at Assets/Scripts/Enemies/EnemyAI.cs:93)
EnemyAI.MoveStateControl () (at Assets/Scripts/Enemies/EnemyAI.cs:62)
EnemyAI.Update () (at Assets/Scripts/Enemies/EnemyAI.cs:38)

I think it’s because the slimes don’t have the “Shooter” class added to them. Should we? and has anyone else noticed this?

Thanks.

If you want the slimes to shoot, then yes, they’ll need a shooter class, but in the course design slimes hurt you by contact (with the PlayeHealth detecting that it’s contacted an enemy and taking damage).

I double checked the Slime’s AI Controller in Stephen’s project, and the slimes have no Enemy Type assigned, and have an attack range of 0. As long as the attack range is zero, the code should never be trying to switch to attacking and access the enemy type.

Yup that did it. If I took the attack damage to 0 then no errors when in play I changed it to 1 and when I got close I got the error.

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

Privacy & Terms