Quantcast
Channel: Unity Forum
Viewing all articles
Browse latest Browse all 1466670

GetComponent returns null when the component exists

$
0
0
I am trying to get a component on the same game object but it keeps returning null.

Script 1 and a CharacterMotor are both attached to 1 game object. In Script 1 I am using the following to get the component.

Code (CSharp):
  1. public CharacterMotor motor;
  2.  
  3. void Start () {
  4.     motor = GetComponent<CharacterMotor> ();
  5.     Debug.Log(motor); // Always null
  6. }
  7.  
But motor is always null. I even require the component for this script and it doesn't throw any errors using...

GetComponent returns null when the component exists

Viewing all articles
Browse latest Browse all 1466670

Trending Articles



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