docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class TargetingComponent

    Manages targeting state, attributes, and release context for the current player session.

    Inheritance
    object
    TargetingComponent
    Implements
    ITargetingContext
    ITargetingActivation
    IServiceComponent
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.Services.Authentication
    Assembly: Unity.Services.Authentication.dll
    Syntax
    public class TargetingComponent : ITargetingContext, ITargetingActivation, IServiceComponent
    Remarks

    Targeting is automatically enabled when any package registers as a consumer via RegisterConsumer(string). This default behavior can be overridden by calling SetEnabled(bool) and restored by calling ClearEnabled().

    Properties

    Attributes

    The targeting attributes that will be sent with the next sign-in or refresh request.

    Declaration
    public Attributes Attributes { get; }
    Property Value
    Type Description
    Attributes

    Enabled

    Whether targeting is currently enabled.

    Declaration
    public bool Enabled { get; }
    Property Value
    Type Description
    bool
    Remarks

    Returns the value set by SetEnabled(bool) if called, otherwise returns true when one or more packages have registered as targeting consumers.

    VariantTags

    The variant tags assigned to this session by the server, or null if no release has been resolved.

    Declaration
    public string[] VariantTags { get; }
    Property Value
    Type Description
    string[]

    Methods

    ClearAppAttributes()

    Clears any custom application attributes previously set by SetAppAttributes(object).

    Declaration
    public void ClearAppAttributes()

    ClearEnabled()

    Clears any value set by SetEnabled(bool), restoring the default behavior where targeting is enabled automatically when registered consumers exist.

    Declaration
    public void ClearEnabled()

    ClearUserAttributes()

    Clears any custom user attributes previously set by SetUserAttributes(object).

    Declaration
    public void ClearUserAttributes()

    RefreshAsync()

    Refreshes the current session using the stored session token, sending targeting attributes if targeting is enabled.

    Declaration
    public Task RefreshAsync()
    Returns
    Type Description
    Task

    A task for the refresh operation.

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the session token does not exist.

    SetAppAttributes(object)

    Sets custom application-scoped attributes to be included in targeting requests.

    Declaration
    public void SetAppAttributes(object appAttributes)
    Parameters
    Type Name Description
    object appAttributes

    An object whose properties will be serialized as application attributes.

    SetEnabled(bool)

    Explicitly enables or disables targeting, overriding the default behavior.

    Declaration
    public void SetEnabled(bool enabled)
    Parameters
    Type Name Description
    bool enabled

    Set to true to enable targeting, or false to disable it.

    Remarks

    By default, targeting is enabled automatically when any package registers as a consumer. Calling this method overrides that behavior. If set to false while registered consumers exist, a warning is logged. Call ClearEnabled() to restore the default consumer-based behavior.

    SetUserAttributes(object)

    Sets custom user-scoped attributes to be included in targeting requests.

    Declaration
    public void SetUserAttributes(object userAttributes)
    Parameters
    Type Name Description
    object userAttributes

    An object whose properties will be serialized as user attributes.

    Implements

    ITargetingContext
    ITargetingActivation
    IServiceComponent
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)