Game.Events.Spectate
Assembly: Assembly-CSharp
Namespace: Game.Events
Type: struct
Base: System.ValueType, Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter
Summary: A lightweight ECS event component used to request that one entity "spectate" (focus or follow) another entity. Typically created as a transient event entity or added to an existing event entity; systems read this component to perform camera or UI changes (switching view target), then consume/remove the event. Implements IQueryTypeParameter so it can be used directly in queries or Entities.ForEach signatures.
Fields
-
public Unity.Entities.Entity m_Event
Represents the event entity that carries this Spectate component. This can be the entity used to manage lifecycle of the event (for example, destroyed after processing) or used to correlate the event with other event data. -
public Unity.Entities.Entity m_Target
The target entity to spectate (e.g., a vehicle, citizen, or other in-game entity). Systems processing this Spectate component should use this field to set camera target, follow behavior, or UI context.
Properties
- This struct does not declare any C# properties. It exposes two public fields instead (
m_Event
andm_Target
), following a common ECS/event pattern for simple data containers.
Constructors
- The struct relies on the implicit parameterless/default constructor provided by C#. No explicit constructors are defined. Initialize instances using an object initializer, e.g. new Spectate { m_Event = e, m_Target = t }.
Methods
- This type does not declare any methods. It is a plain data container (component) intended to be read by systems.
Usage Example
// Create an event entity and add a Spectate component
var spectateEntity = entityManager.CreateEntity(typeof(Spectate));
entityManager.SetComponentData(spectateEntity, new Spectate {
m_Event = spectateEntity,
m_Target = playerVehicleEntity
});
// Example system snippet: consume and remove the event after processing
Entities
.WithAll<Spectate>()
.ForEach((Entity evtEntity, in Spectate spectate) =>
{
// Use spectate.m_Target to set camera focus
CameraSystem.FocusOnEntity(spectate.m_Target);
// Destroy or remove the event entity to mark it consumed
entityManager.DestroyEntity(evtEntity);
}).Run();
{{ Notes: - Treat Spectate as a transient/event component: create it when you want to trigger a one-off spectate action and remove/destroy it after processing. - Because fields are public, you can create and set the component from both authoring and runtime code. - When designing systems that handle these events, consider using a dedicated event entity pool or reuse pattern to avoid transient-entity allocation spikes at runtime. }}