Variant
In OPC UA, a Variant is the self-describing value container that can hold any of the built-in types, or an array or matrix of them. It carries its own type identifier on the wire, so a client can decode a value without prior knowledge of the variable that produced it.
What a Variant can hold
The built-in types are numbered 1 to 25, from Boolean through Byte, the signed and unsigned integers, Float, Double, String, DateTime, Guid, ByteString, XmlElement, NodeId, ExpandedNodeId, StatusCode, QualifiedName, LocalizedText, ExtensionObject, DataValue, Variant and DiagnosticInfo. Anything more complex than these, meaning every server-defined structure, travels as an ExtensionObject inside the Variant. Enumerations travel as Int32, and a custom scalar you modelled as a subtype of Double still arrives as a Double.
Scalars, arrays and matrices
A Variant is a scalar, a one-dimensional array, or a multidimensional matrix carried as a flat array plus a Dimensions field. This is why the node attributes ValueRank and ArrayDimensions exist: they tell a client what shape to expect before it reads. A scalar and a one-element array are different Variants and a server is entitled to reject the wrong one with BadTypeMismatch.
Type matching on write
On Write the server compares the Variant's built-in type against the target node's DataType attribute and its ValueRank. Int16 into an Int32 node, a Double literal into a Float node, or a scalar into an array node are the three mismatches that generate most support tickets. Well-behaved clients read the DataType and ValueRank attributes once at startup and build the Variant to match, rather than relying on the server to coerce.
Null and empty Variants
A Variant can be null, which is distinct from a zero-length array and from a numeric zero. Null Variants appear in a DataValue whose StatusCode is Bad, in optional structure fields that are not present, and in output arguments a method chose not to fill. Client code that unwraps a Variant without checking for null is the usual source of a null reference exception on the first bad quality value.
Example
The three shapes a Variant can take, written as pseudo-values with their type ids
Scalar : Type=11 (Double) Value=42.5
Array : Type=6 (Int32) Value=[1, 2, 3, 4]
Matrix : Type=6 (Int32) Value=[1,2,3,4,5,6] Dimensions=[2,3]
Structure: Type=22 (ExtensionObject) Body=encoded per DataTypeDefinition
Defined in: Part 6 - Mappings, built-in types; Part 3 - Address Space Model for the DataType attribute.
Last verified 7 September 2026 against OPC UA 1.05.07. OPC UA Connect is an educational resource and is not affiliated with the OPC Foundation.