NullReferenceException when using OnMouseUp only

Hello everyone! I can’t seem to find what the cause of the issue is even though I’ve fixed plenty of the same errors before. I’m getting a “NullReferenceException: object reference not set to an instance of an object” only when I try to call on my MoveCharacter function from a OnMouseUp function. Here is the code. Error is at line 45 of TileClickable.

I don’t understand why it is only happening when I call the function from the OnMouseUp. Thank you in advanced and sorry if the code is a little messy, I’m just trying to get a really rough prototype done. Besides, there’s not much code anyways :p.

EDIT: I also have the object I want moved set as selectedUnit already. :slight_smile:

Seems obvious enough - LD is null. You never set it anywhere.

You’re also doing a lot of GetComponent calls for no reason. Cache the results and reuse the variable.

I knew it was going to be something obvious. I was going about it completely the wrong way thanks! I’ve only been coding for about 2.5 weeks now so I’m learning so much at once that I easily forget to do simple stuff.

About caching, I will be doing it eventually, I just want to get my protoyype done before I start refining some of the stuff.