docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct GhostComponentRef<TComponentType>

    This is an optional way to access ECS component data associated with the underlying entity. For GameObject only development, it's simpler to just use GhostField<InternalTypeT> Can be used to share a component type across different GhostBehaviour as they'll be stored on the same shared entity. Can be used to access replicated state from both ECS and GameObject land, since it uses a user defined IComponentData that's not source generated.

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.Netcode
    Assembly: Unity.NetCode.dll
    Syntax
    [Serializable]
    public struct GhostComponentRef<TComponentType> where TComponentType : unmanaged, IComponentData
    Type Parameters
    Name Description
    TComponentType

    The unmanaged component type this reference points to.

    Constructors

    GhostComponentRef(TComponentType)

    Use this constructor to provide an in-code initial value.

    GhostComponentRef<MyComponent> myComp = new (new MyComponent(){ val = 123 });
    Declaration
    public GhostComponentRef(TComponentType initialValue = default)
    Parameters
    Type Name Description
    TComponentType initialValue

    The value the component holds until it is linked to its ghost entity.

    Methods

    Read()

    Returns a copy of the IComponentData this GhostComponentRef<TComponentType> points to. Changes to the copy are not applied until passed to Write(TComponentType).

    Declaration
    public TComponentType Read()
    Returns
    Type Description
    TComponentType

    A copy of the component value.

    Write(TComponentType)

    Writes value to the IComponentData this GhostComponentRef<TComponentType> points to.

    Declaration
    public void Write(TComponentType value)
    Parameters
    Type Name Description
    TComponentType value

    The new component value.

    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)