How to check if a variable contains a Touch?

I have variable named aimFinger of type Touch who’s existence I want to check in an if statement. I have tried doing “if aimFinger == null” or “if(aimFinger)” but they give me an error. So how can I both assign aimFinger to “null”, and check if aimFinger has anything in it?

I’m using C# by the way

The Touch type is a struct which means it’s stored by value, not reference. Therefore there is no concept of a null reference to a Touch struct. You may be able to use C# Nullable Types if you just want to store a read-only Touch (there are issues with modifying Nullable Type structs from what I’ve read).

To use the Nullable Type just add ? to the end of the variable type definition like this:

Touch? aimFinger = null;

You could then process all of the touch inputs and only assign something to aimFinger if the correct touch with the correct touchId exists in Input.touches. I’m guessing you are trying to do something like that.

Note: I haven’t played much with nullable types… this is untested and going off the documentation so questioner beware :slight_smile: