Visual Studio 2015 false alarm out keyword reference types as method arguments

I’m using unity with C# in Visual Studio 2015 and whenever I use something like this:

if (!NavMesh.SamplePosition(position, out NavMeshHit hit, 1f, NavMesh.AllAreas)) { return; }

or this

if (!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity)) { return; }

I get a compile time error warning for RaycastHit hit or NavMeshHit hit and where ever hit is used after that. if I declare it as local variable the error goes away

NavMeshHit hit;
if (!NavMesh.SamplePosition(position, out hit, 1f, NavMesh.AllAreas)) { return; }

RaycastHit hit;
if (!Physics.Raycast(ray, out hit, Mathf.Infinity)) { return; }

or by pressing Ctrl + . and then Esc canceling it, the error goes away and even if it doesn’t, it just compiles OK and goes into run-time with no problem.

is there a way to resolve this inside visual studio?


It’s a C# 7 feature not available in Visual Studio 2015, you have to whether upgrade to 2017 or just ignore it.

EDIT: ended up using Visual Studio Code at the end, coz for me Visual Studio 2017 was too much of a size, 50GB compared to 2015 with only 9GB

Leave a Reply

Your email address will not be published. Required fields are marked *