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
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. |