docs.unity3d.com
    Show / Hide Table of Contents

    Struct ArSession

    Represents the context for an ARCore session.

    Inherited Members
    ValueType.ToString()
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetType()
    Namespace: UnityEngine.XR.ARCore
    Syntax
    public struct ArSession : IEquatable<ArSession>
    Remarks

    This is an opaque object that represents a native ArSession.

    Properties

    IsNull

    (Read Only) Indicates whether this ArSession is null. This property is deprecated. Use the equality operator (==) to compare with null instead.

    Declaration
    [Obsolete("Compare to null instead.")]
    public readonly bool IsNull { get; }
    Property Value
    Type Description
    Boolean

    Null

    Represents a null ArSession, i.e., one whose underlying native pointer is null. This property is obsolete. Use default instead.

    Declaration
    [Obsolete("Use default instead.")]
    public static readonly ArSession Null { get; }
    Property Value
    Type Description
    ArSession

    playbackStatus

    (Read Only) The playback status.

    Declaration
    public readonly ArPlaybackStatus playbackStatus { get; }
    Property Value
    Type Description
    ArPlaybackStatus

    Whether or not the session is playing back a recording (or has stopped because of an error).

    recordingStatus

    (Read Only) The current recording status.

    Declaration
    public readonly ArRecordingStatus recordingStatus { get; }
    Property Value
    Type Description
    ArRecordingStatus

    Whether or not the session is recording (or has stopped because of an error).

    Methods

    AsIntPtr()

    Gets the underlying native pointer for this ArSession.

    Declaration
    public IntPtr AsIntPtr()
    Returns
    Type Description
    IntPtr

    Returns the underlying native pointer for this ArSession.

    Equals(Object)

    Tests for equality.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    Object obj

    An Object to compare against.

    Returns
    Type Description
    Boolean

    Returns true if obj is an ArSession and it compares equal to this one using Equals(ArSession).

    Overrides
    ValueType.Equals(Object)

    Equals(ArSession)

    Tests for equality.

    Declaration
    public bool Equals(ArSession other)
    Parameters
    Type Name Description
    ArSession other

    The ArSession to compare against.

    Returns
    Type Description
    Boolean

    Returns true if the underlying native pointers are the same. Returns false otherwise.

    Implements
    IEquatable<T>.Equals(T)
    Remarks

    Two ArSessions are considered equal if their underlying pointers are equal.

    FromIntPtr(IntPtr)

    Creates an ArSession from an existing native pointer. The native pointer must point to an existing ArSession.

    Declaration
    public static ArSession FromIntPtr(IntPtr value)
    Parameters
    Type Name Description
    IntPtr value

    A pointer to an existing native ArSession.

    Returns
    Type Description
    ArSession

    Returns an ArSession whose underlying native pointer is value.

    GetHashCode()

    Generates a hash code suitable for use with a HashSet or Dictionary

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32

    Returns a hash code for this ArSession.

    Overrides
    ValueType.GetHashCode()

    SetPlaybackDataset(String)

    Sets an MP4 dataset file to playback instead of live camera feed.

    Declaration
    public ArStatus SetPlaybackDataset(string path)
    Parameters
    Type Name Description
    String path

    A file path to a MP4 dataset file or null to use the live camera feed.

    Returns
    Type Description
    ArStatus
    • Returns Success if successful.
    • Returns ErrorSessionNotPaused if called when session is not paused.
    • Returns ErrorSessionUnsupported if playback is incompatible with selected features.
    • Returns ErrorPlaybackFailed if an error occurred with the MP4 dataset file such as not being able to open the file or the file is unable to be decoded.
    Remarks

    Restrictions:

    • Can only be called while the session is paused. Playback of the MP4 dataset file starts once the session is resumed.
    • The MP4 dataset file must use the same camera facing direction as is configured in the session.

    When an MP4 dataset file is set:

    • All existing trackables (i.e., anchors and trackables) immediately enter tracking state TrackingState.None.
    • The desired focus mode is ignored, and does not affect the previously recorded camera images.
    • The current camera configuration is immediately set to the default for the device the MP4 dataset file was recorded on.
    • Calls to retrieve the supported camera configurations return camera configs supported by the device the MP4 dataset file was recorded on.
    • Setting a previously obtained camera config has no effect.

    StartRecording(ArRecordingConfig)

    Starts a new MP4 dataset file recording that is written to the specific filesystem path.

    Declaration
    public ArStatus StartRecording(ArRecordingConfig recordingConfig)
    Parameters
    Type Name Description
    ArRecordingConfig recordingConfig

    The configuration defined for recording.

    Returns
    Type Description
    ArStatus

    Returns Success if successful. Returns one of the following values otherwise:

    • ErrorIllegalState
    • ErrorInvalidArgument
    • ErrorRecordingFailed
    Remarks

    Existing files are overwritten.

    The MP4 video stream (VGA) bitrate is 5Mbps (40Mb per minute).

    Recording introduces additional overhead and may affect app performance.

    StopRecording()

    Stops recording and flushes unwritten data to disk. The MP4 dataset file is ready to read after this call.

    Declaration
    public ArStatus StopRecording()
    Returns
    Type Description
    ArStatus

    Returns Success if successful. Returns ErrorRecordingFailed otherwise.

    Remarks

    Recording can be stopped automatically when the session is paused, if auto stop is enabled via SetAutoStopOnPause(ArSession, Boolean). Recording errors that would be thrown in StopRecording() are silently ignored on session pause.

    Operators

    Equality(Nullable<ArSession>, Nullable<ArSession>)

    Tests for equality.

    Declaration
    public static bool operator ==(ArSession? lhs, ArSession? rhs)
    Parameters
    Type Name Description
    Nullable<ArSession> lhs

    The nullable ArSession to compare with rhs.

    Nullable<ArSession> rhs

    The nullable ArSession to compare with lhs.

    Returns
    Type Description
    Boolean

    Returns true if any of these conditions are met:

    • lhs and rhs are both not null and their underlying pointers are equal.
    • lhs is null and rhs's underlying pointer is null.
    • rhs is null and lhs's underlying pointer is null.
    • Both lhs and rhs are null.

    Returns false otherwise.

    Remarks

    This equality operator lets you to compare an ArSession with null to determine whether its underlying pointer is null. This allows for a more natural comparison with the native ARCore object:

    bool TestForNull(ArSession obj)
    {
        if (obj == null)
        {
            // obj.AsIntPtr() is IntPtr.Zero
        }
    }

    Equality(ArSession, ArSession)

    Tests for equality. Same as Equals(ArSession).

    Declaration
    public static bool operator ==(ArSession lhs, ArSession rhs)
    Parameters
    Type Name Description
    ArSession lhs

    The ArSession to compare with rhs.

    ArSession rhs

    The ArSession to compare with lhs.

    Returns
    Type Description
    Boolean

    Returns true if lhs is equal to rhs using Equals(ArSession). Returns false otherwise.

    Explicit(ArSession to IntPtr)

    Casts an ArSession to its underlying native pointer.

    Declaration
    public static explicit operator IntPtr(ArSession session)
    Parameters
    Type Name Description
    ArSession session

    The ArSession to cast.

    Returns
    Type Description
    IntPtr

    Returns the underlying native pointer for session

    Inequality(Nullable<ArSession>, Nullable<ArSession>)

    Tests for inequality.

    Declaration
    public static bool operator !=(ArSession? lhs, ArSession? rhs)
    Parameters
    Type Name Description
    Nullable<ArSession> lhs

    The native object to compare with rhs.

    Nullable<ArSession> rhs

    The native object to compare with lhs.

    Returns
    Type Description
    Boolean

    Returns false if any of these conditions are met:

    • lhs and rhs are both not null and their underlying pointers are equal.
    • lhs is null and rhs's underlying pointer is null.
    • rhs is null and lhs's underlying pointer is null.
    • Both lhs and rhs are null.

    Returns true otherwise.

    Remarks

    This inequality operator lets you to compare an ArSession with null to determine whether its underlying pointer is null. This allows for a more natural comparison with the native ARCore object:

    bool TestForNull(ArSession obj)
    {
        if (obj != null)
        {
            // obj.AsIntPtr() is not IntPtr.Zero
        }
    }

    Inequality(ArSession, ArSession)

    Tests for inequality. Same as the negation of Equals(ArSession).

    Declaration
    public static bool operator !=(ArSession lhs, ArSession rhs)
    Parameters
    Type Name Description
    ArSession lhs

    The ArSession to compare with rhs.

    ArSession rhs

    The ArSession to compare with lhs.

    Returns
    Type Description
    Boolean

    Returns false if lhs is equal to rhs using Equals(ArSession). Returns true otherwise.

    See Also

    beforeSetConfiguration
    ARCoreBeforeSetConfigurationEventArgs
    beforeGetCameraConfiguration
    ARCoreBeforeGetCameraConfigurationEventArgs
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023