docs.unity3d.com
    Show / Hide Table of Contents

    Class ComponentUtils

    Utility class for working with Components

    Inheritance
    Object
    ComponentUtils
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.XR.CoreUtils
    Syntax
    public static class ComponentUtils

    Methods

    GetOrAddIf<T>(GameObject, Boolean)

    Get a component from a GameObject, or add a new one and return it, if specified

    Declaration
    public static T GetOrAddIf<T>(GameObject gameObject, bool add)
        where T : Component
    Parameters
    Type Name Description
    GameObject gameObject

    The GameObject from which the component will be retrieved, or to which a new one will be added

    Boolean add

    Whether to add a new component of the given type, if one does not already exist

    Returns
    Type Description
    T

    The new or retrieved component

    Type Parameters
    Name Description
    T

    The type of component to get or add

    Back to top
    Terms of use
    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