Unity Throws Null, when it is not Null actually. (unity 5.5.2f)

public foo(Location startLocation, Location destinations, int populationCount)
{
UnityEngine.Debug.Log (startLocation); //prints (50, 50)
if (startLocation == null)
throw new ArgumentNullException(“startLocation”); //throws exception
}

edit(moved from comment)

This is the Location class:

public class Location : MonoBehaviour 
{
    public float X { get; private set; }
    public float Y { get; private set; }
 
    public Location(float x, float y)
    {
        X = x;
        Y = y;
    }
}

Well, your question is lacking important information. Specifically what that Location class is.

I guess that you have derived your Location class from UnityEngine.Object or any other derived class like MonoBehaviour. That would explain this behaviour. You must never derive a class directly from UnityEngine.Object. That class is a reserved base class for Unity’s internal classes. Also MonoBheaviour and ScriptableObject derived classes must not be created with “new”. MonoBehaviours are components and can only exist as part of a GameObject. They can only be created with “AddComponent” or by dragging the script onto a gameobject in the editor. ScriptableObjects must be created with the “CreateInstance” method.

However if your “Location” class is a pure data class, it shouldn’t be derived from any class.

If you need a more detailed answer you have to post how your Location class looks like. If you are confused why your class “seems” to equal null, see this blog post of Unity about the overloaded == operator.

ps: Unity doesn’t “throw null”. You throw an ArgumentNullException manually.

edit

Well, as i though you derived your class from MonoBehaviour. That doesn’t make much sense for this class. MonoBehaviours can’t be created with “new”. They are components and need to be attached to a GameObject. You should remove that inheritance from your class.

public class Location
{
    public float X { get; private set; }
    // [ ... ]

public class Location : MonoBehaviour
{
public float X { get; private set; }
public float Y { get; private set; }

	public Location(float x, float y)
	{
		X = x;
		Y = y;
	}
}

@Bunny83 above is my Location class. Thanks for your reply btw.