Created
February 25, 2016 19:52
-
-
Save hunterloftis/f76266f1b0c92bcfba4f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// both the 'Player' component and this component exist as scripts on the player instance in the scene | |
// My guess is that start() is called on this component before on Player() | |
// (even though this script is listed last) | |
// Is this a bad pattern? It seems like running GetComponent() on each FixedUpdate() and checking for null would be a huge waste | |
// How do unity developers do this instead? | |
void start() { | |
player = GetComponent<Player>(); | |
} | |
void FixedUpdate() { | |
player.DoSomething(); // NullReferenceException: Object reference not set to an instance of an object | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment