GetComponent
GetComponent
retrieves the underlying component data for a given entity.
Example
Parameters
Parameter | Type | Description |
---|
T | type parameter | A registered component struct that implements the Name method |
worldCtx | WorldContext | A WorldContext object passed in to your system or Query definition |
id | EntityID | The ID of the entity from which to retrieve the component data. |
Return Values
Type | Description |
---|
T | The retrieved component data. |
error | An error indicating any issues during retrieval. |
SetComponent
SetComponent
sets the component data for a given entity.
Example
Parameters
Parameter | Type | Description |
---|
T | type parameter | A registered component struct that implements the Name method |
worldCtx | WorldContext | A WorldContext object passed in to your system or query definition |
id | EntityID | Entity ID of the entity to set the component data for. |
component | T | Component value to set for the entity. |
Return Value
Type | Description |
---|
error | An error indicating any issues during the operation. |
UpdateComponent
UpdateComponent
enables modification of the underlying component data in a single function call. Update
uses Get
and Set
under the hood.
Example
Parameters
Parameter | Type | Description |
---|
T | type parameter | A registered component struct that implements the Name method |
worldCtx | WorldContext | A WorldContext object passed in to your system or query definition |
id | EntityID | ID of the entity to perform the component update on. |
fn | func(*T) *T | Function that modifies the component’s value. |
Return Value
Type | Description |
---|
error | An error indicating any issues during the operation. |
RemoveComponentFrom
RemoveComponentFrom
removes the component from the given entity. An error will be returned if the entity does not have the component.
Example
Parameters
Parameter | Type | Description |
---|
T | type parameter | A registered component struct that implements the Name method |
worldCtx | WorldContext | A WorldContext object passed in to your system or query definition |
id | EntityID | Entity ID of the entity to remove the component from. |
Return Value
Type | Description |
---|
error | Returns an error if the operation encounters an issue. |
AddComponentTo
AddComponentTo
adds the component to a given entity. An error will be returned if the entity already has the component.
Example
Parameters
Parameter | Type | Description |
---|
T | type parameter | A registered component struct that implements the Name method |
worldCtx | WorldContext | A WorldContext object passed in to your system or query definition |
id | EntityID | Entity ID of the entity to add the component to. |
Return Value
Type | Description |
---|
error | Returns an error if the operation encounters an issue. |