Game.Tutorials.TutorialRef
Assembly:
Assembly-CSharp (game assembly)
Namespace:
Game.Tutorials
Type:
struct
Base:
Unity.Entities.IBufferElementData
Summary:
A simple buffer element that holds a reference to a tutorial Entity. Use this struct with DynamicBuffer
Fields
public Unity.Entities.Entity m_Tutorial
Holds the referenced tutorial Entity. Default value is Entity.Null when the buffer element is default-constructed. This field is mutable and intended to be read/written when iterating over a DynamicBuffer.
Properties
- None
Constructors
public TutorialRef(Unity.Entities.Entity tutorial)
Creates a new buffer element that references the provided tutorial entity.
Methods
- None
Usage Example
using Unity.Entities;
using Game.Tutorials;
// Add a TutorialRef buffer to a host entity and add a tutorial reference
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity host = /* obtain or create host entity */;
Entity tutorialEntity = /* obtain or create tutorial entity */;
// Ensure the host has the buffer
var buffer = em.GetBuffer<TutorialRef>(host); // AddBuffer<TutorialRef>(host) if not present
buffer.Add(new TutorialRef(tutorialEntity));
// Example System usage: iterate DynamicBuffer<TutorialRef>
public partial class TutorialProcessorSystem : SystemBase
{
protected override void OnUpdate()
{
Entities
.ForEach((in Entity entity, in DynamicBuffer<TutorialRef> tutorials) =>
{
foreach (var tr in tutorials)
{
Entity tut = tr.m_Tutorial;
if (tut != Entity.Null)
{
// process tutorial entity
}
}
})
.ScheduleParallel();
}
}
{{ This struct is intended to be lightweight and used purely as a container for Entity references inside an ECS DynamicBuffer. Because it implements IBufferElementData it can be used in jobs and scheduled work; access should follow the usual Entity Component System safety rules (use DynamicBuffer in job contexts or SystemBase lambdas as shown). }}