C# out hit for raycasthit - why is the out needed, what does it go

I notice that RaycastHit is called differently for JS vs C#… In C#, the hit is actually out hit … what does the out do, and why is it needed?

Most function arguments are passed by value – that is, you pass a copy of the original value, rather than the variable itself. Changes made to that copy won’t be reflected in the original variable unless your code does so explicitly.

Some functions accept arguments that are passed by reference – instead of a copy, you pass the original variable itself. Changes made in the called function will be reflected in the original variable.

C# and UnityScript both typically pass by value, unless the called function explicitly tells the compiler to pass by reference. C# is unique in that it requires coders to explicitly pass by reference on both sides of the call – I assume the idea is to make sure that you know you’re doing so, as it can sometimes lead to confusion.

Ultimately, both languages are doing the same thing. C# just has a slightly different syntax for doing so.

As far as I know, the Out gives you the info about what it hit, like the distance to the hit, the name of the object it hit, the point where it hit, and so on.

It can be very helpful in some cases where you wanna know if a laser hit a friendly target or an enemy, for example.