Game.Objects.Destroy
Assembly:
Unknown (defined in the mod/game code - compiled into the mod's assembly)
Namespace: Game.Objects
Type: struct
Base: IComponentData, IQueryTypeParameter
Summary: Represents a destroy request/component that ties an object entity (the target to be destroyed) to an event entity (the source or trigger of the destruction). This is a plain ECS component (blittable) intended for use with Unity DOTS systems: systems can query for entities carrying this component and perform destruction or related logic when encountered.
Fields
-
public Entity m_Object
This is an Entity handle that identifies the object (entity) that should be destroyed. Treat this as an ID — verify that the entity is valid before operating on it (e.g., EntityManager.Exists). -
public Entity m_Event
This is an Entity handle representing the event or originator of the destruction (for example, an event entity containing context, who/what caused the destruction, or a request ticket). Systems can use this to correlate the destroy request with additional data or to remove/complete the event entity after processing.
Properties
- This type does not define any C# properties. It only exposes the two public fields above.
Constructors
public Destroy(Entity _object, Entity _event)
Constructs a Destroy component instance, setting the target object entity and the associated event entity. Use this when adding the component to an entity via EntityManager/AddComponentData or when creating an entity with this component.
Methods
- This struct defines no methods. It is a plain data container (IComponentData).
Usage Example
using Unity.Entities;
using Game.Objects;
// Example: create a destroy request and attach it to a "request" entity
public void CreateDestroyRequest(EntityManager entityManager, Entity targetObject)
{
// Create an event entity to represent the destroy request (optional)
EntityArchetype eventArchetype = entityManager.CreateArchetype(typeof(Destroy));
Entity eventEntity = entityManager.CreateEntity(eventArchetype);
// Fill the Destroy component linking the target object and the event entity
var destroyComp = new Destroy(targetObject, eventEntity);
// Set component data on the event entity
entityManager.SetComponentData(eventEntity, destroyComp);
// A system should query for entities with Destroy and handle destruction,
// e.g., destroy the targetObject and then destroy eventEntity when processed.
}
Notes and best practices: - As this is an IComponentData, it is meant to be processed by DOTS systems. Implement a system that queries for this component and performs the actual EntityManager.DestroyEntity or other cleanup. - Validate Entity handles (EntityManager.Exists) before performing operations; m_Object or m_Event may be invalid if the entity was already destroyed. - The IQueryTypeParameter marker indicates this component type can be used in queries/filters by systems in DOTS. Use it in Entities.ForEach, ComponentSystemBase queries, or SystemBase queries as appropriate.