Class XRMarkerSubsystem
A subsystem that detects and tracks visual markers in the environment (e.g., QR, ArUco, AprilTag).
Inheritance
Implements
Inherited Members
Namespace: UnityEngine.XR.ARSubsystems
Assembly: Unity.XR.ARSubsystems.dll
Syntax
public class XRMarkerSubsystem : TrackingSubsystem<XRMarker, XRMarkerSubsystem, XRMarkerSubsystemDescriptor, XRMarkerSubsystem.Provider>, ISubsystem
Remarks
This base class must be implemented by providers that supply actual marker detection and tracking.
Constructors
XRMarkerSubsystem()
Do not invoke this constructor directly. Use Unity's subsystem infrastructure to acquire instances.
Declaration
public XRMarkerSubsystem()
Methods
GetChanges(Allocator)
Gets the changes (added, updated, and removed markers) since the last call to this method.
Declaration
public override TrackableChanges<XRMarker> GetChanges(Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
Allocator | allocator | The allocator used to allocate memory for the changes. |
Returns
Type | Description |
---|---|
TrackableChanges<XRMarker> | The set of changes since the last call to this method. |
Overrides
TryGetBytesData(XRSpatialBuffer)
Attempts to get the encoded data of a specific marker, decoded as a byte array.
Declaration
public Result<byte[]> TryGetBytesData(XRSpatialBuffer dataBuffer)
Parameters
Type | Name | Description |
---|---|---|
XRSpatialBuffer | dataBuffer | The spatial buffer of the marker required to retrieve the encoded data. |
Returns
Type | Description |
---|---|
Result<byte[]> | A |
Remarks
To determine if a marker's encoded data is available as binary data, you can check its dataBuffer property. If the bufferType is Uint8, this method should be used to retrieve the encoded data.
This method allocates a new managed byte[]
on each successful call. For performance critical applications
that need to avoid garbage collection, consider using
(TryGetBytesData(XRSpatialBuffer, Allocator)).
TryGetBytesData(XRSpatialBuffer, Allocator)
Attempts to get the encoded data of a specific marker, decoded as a NativeArray_1.
Declaration
public Result<NativeArray<byte>> TryGetBytesData(XRSpatialBuffer dataBuffer, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
XRSpatialBuffer | dataBuffer | The spatial buffer of the marker required to retrieve the encoded data. |
Allocator | allocator | The allocator to use for the returned NativeArray_1. |
Returns
Type | Description |
---|---|
Result<NativeArray<byte>> | A |
Remarks
This method is useful for performance sensitive applications as it avoids managed memory allocations. The caller is responsible for disposing the returned NativeArray_1 for persistent allocators.
TryGetStringData(XRSpatialBuffer)
Attempts to get the encoded data of a specific marker, decoded as a string.
Declaration
public Result<string> TryGetStringData(XRSpatialBuffer dataBuffer)
Parameters
Type | Name | Description |
---|---|---|
XRSpatialBuffer | dataBuffer | The spatial buffer of the marker required to retrieve the encoded data. |
Returns
Type | Description |
---|---|
Result<string> | A |
Remarks
To determine if a marker's encoded data is available as a string, you can check its dataBuffer property. If the bufferType is String, this method should be used to retrieve the encoded data.
Alternatively, if you expect string data (for example, you are scanning QR codes with URLs), you can call this method directly and check the status to see if it was successful.