Unity4, Unityscript added "ref" or "out" keyword?

Attention, advanced Unity developers!!

As you already know, Unityscript does not support passing by ref to functions

Does anyone know,

Have Unity recently added this to Unityscript - perhaps in U4 ??

I tried all the obvious keywords (ref, out, etc)

It is undocumented so maybe they have added it, but I just don’t know the keyword.

Cheers!!

If they'd been added, it would have been in the release notes.

1 Answer

1

Unityscript does not have any way for passing parameters by reference.

If you must have By Ref arguments, C# supports them.

EDIT: Actually, on further investigation, there may be support for these. The built-in function Physics.Raycast() can be in the form

static function Raycast (origin : Vector3, direction : Vector3, out hitInfo : RaycastHit, distance : float = Mathf.Infinity, layerMask : int = kDefaultRaycastLayers) : boolean

Notice the ‘out hitInfo’ argument. This appears to be ByRef. I have no idea how this can be achieved in a custom function, but it does appear to be possible.

EDIT 2: Eric5h5 has kindly offered some clarification in the comments, I’ll sum it up here:
If you define your function in JS/US, it cannot utilise ByRef parameters. However, if your function is defined in C#, you can call it from JS/US with Out parameters that are ByRef.

Hiya. You're quite sure it has not been added in U4 ?

Is it specific to the language, or is it .Net ?

Hey, I clarified the question with more info.

I can't find anything in the reference manual, nor in the change logs, so I would have to say no here.

I've made an amendment. It appears my information was not entirely accurate.