Argument Attributes not Working

gyltefors 3 years ago updated 3 years ago 9

Method arguments that use the [Out] attribute in front of the argument name do not appear on Bolt units.

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
Pending Review

If they are out arguments, they will appear as outputs, as they should, because they're not specifiable on calling, they're return values. Unless I'm misunderstanding?

It is not an out argument like

  someMethod(out float[] values)

but rather the [Out] attribute, like

  someMethod([Out] float[] values)

I see! It's odd, there's no special handling of OutAttribute anywhere in the source. I'll have to investigate. In the mean time, can you create a wrapper around your P/Invoke method?

Thanks, yes, I created a wrapper for the method for now.

Fixed in Next Version

Hi gyltefors, sorry for the late reply on this.

From my understanding on P/Invoke and [Out], you are expecting the array parameter to show up as an output, is that right?

Your parameter kind of falls between the cracks currently for Bolt. ParameterInfo.ParameterType.IsByRef returns false, because it's not marked as out or ref, so Bolt doesn't show it as an output. But ParameterInfo.IsOut returns true, because it has the [Out] attribute, so Bolt hides it as an input.

I've had to do a little bit on research to understand how Bolt should even behave in that case. My conclusion is that:

  • Your parameter should probably be marked as [Out] out anyway, or just out which implicitly specifies [Out], so that the marshalling behaviour matches the C# compiler checking.
  • But at the same time, calling this method should work without out specified. Bolt would fill in a null for the value, which should work if your native code works properly and indeed doesn't expect a value.
  • Therefore Bolt should show your parameter as an output anyway, even if it is not ByRef, but becuase it is Out. This is a change I'll implement in v.1.4.0f10.

So your method will look like this:

Hi, thanks for the follow up. Houdini API is using "[Out]" extensively, and as it differs from "out" an input parameter has to be supplied. I think the best solution might be to ignore "[Out]", and just provide inputs and outputs as normal.

That's odd, I believe it's a mistake from Houdini's side then. A P/Invoke parameter marked as [Out] indicates that the argument will not be provided by the caller, and that it will be assigned by the callee. Unless I misunderstood?

Can you give me an example of how you would be supposed to call one of those methods in Houdini's API?

Sorry for the delay in responding. The original API is a C API documented here:


As the Unity API is commercial, I can't copy paste the full code, but e.g the data array is declared in C-Sharp as:

[Out] double[] data_array

The array has to be created and passed to the method, who fills in the values.