docs.unity.cn
    Show / Hide Table of Contents

    Struct WeakObjectReference<TObject>

    Weak reference to an object. This allows control over when an object is loaded and unloaded.

    Namespace: Unity.Entities.Content
    Syntax
    [Serializable]
    public struct WeakObjectReference<TObject> : IEquatable<WeakObjectReference<TObject>> where TObject : Object
    Type Parameters
    Name Description
    TObject

    The type of UnityEngine.Object this reference points to.

    Constructors

    Name Description
    WeakObjectReference(TObject)
    WeakObjectReference(UntypedWeakReferenceId)

    Weak reference to an object.

    Properties

    Name Description
    IsReferenceValid

    Returns true if the reference has a valid id. In the editor, additional checks for the correct GenerationType and the existence of the referenced asset are performed.

    LoadingStatus

    Get the loading status of the referenced object.

    Result

    The value of the referenced object. This returns a valid object if IsLoaded is true.

    Methods

    Name Description
    Equals(WeakObjectReference<TObject>)
    GetHashCode()

    Gets the hash code of this reference.

    LoadAsync()

    Directs the object to begin loading. This will increase the reference count for each call to the same id. Release must be called for each Load call to properly release resources.

    Release()

    Releases the object. This will decrement the reference count of this object. When an objects reference count reaches 0, the archive file is released. The archive file is only unloaded when its reference count reaches zero, which will then release the archive it was loaded from. Archives will be unmounted when their reference count reaches 0.

    ToString()

    String conversion override.

    WaitForCompletion(Int32)

    Wait for object load in main thread. This will force synchronous loading and may cause performance issues.

    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on Wednesday, September 20, 2023