logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityObjectUtils

    Small, generalized helpers for Unity object identity checks and component lookup, factored out of the per-service copies that used to hand-roll them (e.g. the destroyed-object-aware null check that used to live only in UnityAssetPrefetcherService).

    Inheritance
    object
    UnityObjectUtils
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.Global.Infrastructure.Utils
    Assembly: Serenity.UnityGlobal.Infrastructure.dll
    Syntax
    public static class UnityObjectUtils

    Methods

    GetOrAddComponent<TComponent>(Component)

    Returns the existing TComponent on sibling's GameObject, or adds one if none is present.

    Declaration
    public static TComponent GetOrAddComponent<TComponent>(this Component sibling) where TComponent : Component
    Parameters
    Type Name Description
    Component sibling
    Returns
    Type Description
    TComponent
    Type Parameters
    Name Description
    TComponent

    GetOrAddComponent<TComponent>(GameObject)

    Returns the existing TComponent on host, or adds one if none is present.

    Declaration
    public static TComponent GetOrAddComponent<TComponent>(this GameObject host) where TComponent : Component
    Parameters
    Type Name Description
    GameObject host
    Returns
    Type Description
    TComponent
    Type Parameters
    Name Description
    TComponent

    IsAlive(object)

    True when candidate is non-null — and, when it is a UnityEngine.Object, not destroyed either (Unity's "fake null" case: a managed reference to a native object that has already been destroyed is correctly treated as gone instead of passing a plain reference-null check).

    Declaration
    public static bool IsAlive(object candidate)
    Parameters
    Type Name Description
    object candidate
    Returns
    Type Description
    bool
    In this article
    © 2026 Serenity. All Rights Reserved