Question about reference in parameter

I’m not understanding why OutHitResult variable is needed to be reference.

Even if I don’t use reference like GetGrabbableInReach(FHitResult OutHitResult),
won’t function still return first hit object to OutHitResult variable and then to HitResult in Grab function?
but it makes editor crash, and I’m assuming HitResult are not getting the first hit object. Why?

Doesn’t variable needs to be same with parameter?
Why isn’t HitResult declared as reference?

Can anyone help me understand this?
Thanks in advance.

Reference parameters are used so you can pass in a variable to a method and that method can then update the variable. If it was not a reference parameter, any changes inside the method would not be returned. This is also useful when you need multiple return values from a single method. You could create a structure or class to encapsulate them all but this can be a cleaner way, especially for single use situations.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms