Game.Tutorials.TutorialTrigger
Assembly: Assembly-CSharp.dll
Namespace: Game.Tutorials
Type: struct
Base: System.ValueType, Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter
Summary:
A lightweight ECS component that stores a reference to an Entity acting as a tutorial trigger. Attach this component to an entity to link it to another entity that represents the trigger (for example, a trigger volume, hotspot, or UI element). Systems can query for this component to handle tutorial logic (activation, progress, completion) when the referenced trigger entity is interacted with or activated by the player.
Fields
public Unity.Entities.Entity m_Trigger
Holds the Entity that functions as the tutorial trigger. Typically this is the entity representing a trigger volume or interactive object. If unset, the default value is Entity.Null. Systems should check for Entity.Null before using the reference.
Properties
- None.
This struct only exposes the public field m_Trigger and does not define any properties.
Constructors
public TutorialTrigger()
Implicit parameterless constructor provided by the C# compiler for value types. When constructed via this default, m_Trigger will be Entity.Null. You can create an initialized instance by using the object initializer syntax: new TutorialTrigger { m_Trigger = someEntity }.
Methods
- None.
This component is a plain data container (IComponentData) and does not define methods. Behavior is implemented in systems that read or write this component.
Usage Example
using Unity.Entities;
using Game.Tutorials;
// Example: add a TutorialTrigger component to an entity and set the trigger entity reference
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity tutorialEntity = entityManager.CreateEntity();
Entity triggerVolumeEntity = /* create or obtain trigger volume entity */ Entity.Null;
// attach the component and set the trigger reference
entityManager.AddComponentData(tutorialEntity, new TutorialTrigger { m_Trigger = triggerVolumeEntity });
// Example system consumption (SystemBase)
public partial class TutorialSystem : SystemBase
{
protected override void OnUpdate()
{
Entities
.WithAll<TutorialTrigger>()
.ForEach((Entity e, in TutorialTrigger tt) =>
{
if (tt.m_Trigger == Entity.Null) return;
// perform checks or respond to the trigger entity (e.g., query its components)
// advance tutorial, show hint, etc.
})
.Schedule();
}
}
Additional notes: - Because this is an IQueryTypeParameter as well as IComponentData, it can be used directly in certain query patterns for filtering/reading in Systems. - Validate m_Trigger before dereferencing to avoid using Entity.Null. - Use this component to decouple tutorial logic from the physical trigger entity; one entity can reference another to represent the trigger relationship.