Game.Common.Event
Assembly: Assembly-CSharp
Namespace: Game.Common
Type: struct
Base: System.ValueType, implements Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter
Summary:
A zero-data "tag" or marker component used to represent a transient event in ECS. The struct is explicitly laid out with Size = 1 byte so it can be used as a minimal footprint component for signaling. Because it implements IQueryTypeParameter it can be used directly in query construction (e.g., WithAll
Fields
- None. {{ This struct declares no fields; the StructLayout attribute sets its size to 1 byte even though it contains no managed fields. That is an intentional optimization for tag components. }}
Properties
- None. {{ There are no properties on this type. It is an empty tag component. }}
Constructors
- Implicit default constructor (value-type default) {{ As a struct, Event has the implicit default constructor that initializes it to its default value. You can construct it with "new Event()" when adding component data, but no state is stored. }}
Methods
- None. {{ No instance or static methods are defined. Interaction is via ECS APIs (add/remove/query) rather than methods on the type. }}
Usage Example
using Unity.Entities;
// Add the tag to an entity (EntityManager)
entityManager.AddComponentData(entity, new Game.Common.Event());
// or
entityManager.AddComponent(entity, typeof(Game.Common.Event));
// Query entities that have the Event tag in a SystemBase
public partial class EventProcessingSystem : SystemBase
{
protected override void OnUpdate()
{
// Example: process all entities with the Event tag, then remove the tag
var ecb = new EntityCommandBuffer(Unity.Collections.Allocator.Temp);
Entities
.WithAll<Game.Common.Event>()
.ForEach((Entity entity) =>
{
// Handle the event for 'entity' here
// Remove the tag so the event is one-frame only
ecb.RemoveComponent<Game.Common.Event>(entity);
}).Run();
ecb.Playback(EntityManager);
ecb.Dispose();
}
}
{{ Best practices: treat this as a one-frame event marker. For thread-safe adds/removes, use an EntityCommandBuffer or the parallel ECB variant. Avoid storing state in tag components; use separate components for persistent data. }}