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

GetComponent null reference C#

$
0
0
I have 2 scripts attached to a cube I'm trying to get variables from the other script,but it always comes up null. in the start function of the script , physics, I have void Start () { script = transform.parent.GetComponent(); } The MonoScript editor suggests Class Movement , but when I run it I get a null reference exception. Then I can not use any of Movement's variables. oops forgot to mention that this was in C#. twisted's suggestion let's me access the variables in the editor, but when I actually run Unity it still throws an error. Thanks thought I had use parent , when I didn't. This worked Movement script; // Use this for initialization void Start () { script = GetComponent() as Movement; }

Viewing all articles
Browse latest Browse all 470

Trending Articles



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