Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

NullReferenceException from bullets hitting their targets?

$
0
0
I'm getting a NullReferenceException error when my instantiated bullets hit their targets, saying "Object reference not set to an instance of an object". It isn't affecting the gameplay, but it doesn't sit right having any sort of error occurring. Double clicking on the error directs me to this line of code: `if(collision.gameObject.transform.parent.gameObject == target)` I realize this looks a bit complicated and that's probably why I'm getting the errors. Basically, this code is from a scripts attached to the bullets, inside an OnTriggerEnter2D method. If it collides with the "target's" hurtbox (which is a child of the target) it gets the parent and runs this code. Inside the if statement is the following code:` target.GetComponent().TakeDamage(damage); Destroy(gameObject); ` and in case you were wondering, the "target" is assigned when the bullet is instantiated, and performs all of its intended interactions, but I'm still getting this error.

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>