Game.Areas.Terrain
Assembly:
Assembly-CSharp (typical Unity/game assembly — verify in your project if this type is placed in a different assembly)
Namespace: Game.Areas
Type: struct
Base: System.ValueType — implements IComponentData, IQueryTypeParameter, IEmptySerializable
Summary: Terrain is an empty/marker ECS component (a "tag" component) used to mark or identify entities that represent terrain areas. The struct is attributed with StructLayout(LayoutKind.Sequential, Size = 1) to ensure it occupies a non-zero size (useful for certain serialization/storage expectations) and to keep it blittable for DOTS/serialization systems. It implements Unity.Entities.IComponentData (so it can be attached to entities), IQueryTypeParameter (to be used in query construction), and Colossal.Serialization.Entities.IEmptySerializable (integration with the game's serialization utilities).
Fields
- This type defines no fields.
Terrain is intentionally empty; its presence/absence on an entity is the meaningful data.
Properties
- This type defines no properties.
As a plain tag component, no runtime state is stored on the type itself.
Constructors
- public Terrain()
Structs have an implicit parameterless constructor. Use new Terrain() to create the tag value when adding it via APIs that require a value (AddComponentData).
Methods
- This type declares no methods.
The implemented interfaces are marker/serialization interfaces and do not add instance members here.
Usage Example
using Unity.Entities;
using Game.Areas;
// 1) Add as a tag to an existing entity using EntityManager
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
entityManager.AddComponentData(someEntity, new Terrain());
// 2) Create an entity that includes the Terrain tag as part of an archetype
EntityArchetype archetype = entityManager.CreateArchetype(typeof(Terrain), typeof(Translation));
Entity terrainEntity = entityManager.CreateEntity(archetype);
// 3) Add via an EntityCommandBuffer inside a system
public partial class ExampleSystem : SystemBase
{
EndSimulationEntityCommandBufferSystem _ecbSystem;
protected override void OnCreate()
{
_ecbSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
}
protected override void OnUpdate()
{
var ecb = _ecbSystem.CreateCommandBuffer().AsParallelWriter();
Entities
.WithName("TagTerrainEntities")
.ForEach((Entity entity, int entityInQueryIndex, ref SomeComponent comp) =>
{
// conditionally tag an entity as Terrain
if (comp.someFlag)
ecb.AddComponent<Terrain>(entityInQueryIndex, entity);
}).ScheduleParallel();
_ecbSystem.AddJobHandleForProducer(Dependency);
}
}
// 4) Querying entities that have the Terrain tag
Entities.WithAll<Terrain>().ForEach((Entity e, ref Translation t) =>
{
// operate on terrain entities
}).Schedule();
Notes:
- Because Terrain is empty, the presence of the component is used as the signal. Use WithAll