Quantcast
Channel: Questions in topic: "exception"
Viewing all articles
Browse latest Browse all 470

How to correctly handle NullReferenceException when using GetComponent?

$
0
0
I have tried using: TestComponent temp = gameObject.GetComponent(); if (temp != null) { //...do things } However, it gives me an error when I first try to use GetComponent. I can suppress the error with try/catch block, but what is the way to handle it if I do not have a way to be sure that the object has specific component?

Viewing all articles
Browse latest Browse all 470

Trending Articles



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