I was trying out something compact like a shader
to cut on the verbosity of unpacking results
but
Assets\BlissManagerOld.cs(251,58): error CS1061: 'int4' does not contain a definition for 'Deconstruct' and no accessible extension method 'Deconstruct' accepting a first argument of type 'int4' could be found (are you missing a using directive or an assembly reference?)
Would an extension work?
"Deconstruct " uses Tuple which is a Reference Type, so sadly it can not be used in bursted code. So even if int4 can be “Deconstruct” it will still not work.
I want to be able to use this c# feature too. maybe burst should try to replace them with ValueTuple or simply regenerate equivalent assembly using scalar values. When the team has the time…
you can deconstruct any type by having an instance or extension method with the appropriate out parameters.
thisvar (a, b, c) = foo;
is just sintactic sugar for foo.Deconstruct(out var a, out var b, out var c);
, and the compiler uses pattern matching (/duck typing) for this feature.
you can declare an extension method like this yourself
public void Deconstruct(this int4 value, out int x, out int y, out int z, out int w) {
x = value.x;
y = value.y;
z = value.z;
w = value.w;
}
and it will work
no.
- as written above, Deconstruct does not uses tuples
- this [icode=CSharp]var (x, y, z) = (1, 2, 3);[/icode] already uses
ValueTuple
for the rhs, thenvalueTuple.Deconstruct(...)
for the assigmnents. if it is not still burstable, it would be because ValueTuple in unity .net library hasLayoutKind.Auto
(I last checked a long time ago, it may be fixed)
you can also provide your own struct System.ValueTuple, and the C# compiler will use that for code with tuple syntax.