[Solved] NullReferenceException for paddle in Ball.cs

I’m following this course in Unity 5.4.0f3. I’m pretty sure I’ve done everything the same as in the videos apart from a few changes due to deprecated functions. I’ve just finished Lecture 75, “Launching Ball on Mouse Click.”

I’m getting “NullReferenceException: Object reference not set to an instance of an object” on lines 12 and 18 but the code runs, all of the test values I’ve tried pulling from it are accurate, and the ball stays in the same position relative to the paddle as intended.

The Paddle GameObject is correctly set as the reference for Ball (Script) in Inspector.

This is what I have in Ball.cs:

Figured it out. Somewhere along the way another instance of Ball.cs got attached to another GameObject and was running on its own there without a reference.

1 Like