Game.SharedMeshData
Assembly:
Assembly-CSharp (default Unity assembly; may be different if your project uses assembly definitions)
Namespace:
Game.Prefabs
Type:
struct
Base:
Implements Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter
Summary:
A simple ECS component that stores a reference to a mesh Entity used by prefabs. This component is a plain (blittable) data container intended for use with Unity's Entities (DOTS) systems in Cities: Skylines 2 modding. It allows systems to associate or look up a shared mesh Entity for rendering or instancing logic. Because it implements IQueryTypeParameter it can be used directly in query/type parameter contexts.
Fields
public Unity.Entities.Entity m_Mesh
Holds the Entity reference to the mesh. Typically this will be an Entity that owns mesh data (e.g., a shared mesh prefab/asset Entity). When not set, this should be treated as Unity.Entities.Entity.Null.
Properties
- None.
This struct exposes a single public field and does not declare properties.
Constructors
- Default struct constructor (implicit)
By default the struct is value-initialized; m_Mesh will be Entity.Null unless explicitly set.
You can create an instance using object initializer syntax: new SharedMeshData { m_Mesh = meshEntity };
Methods
- None.
This component is a plain data container and does not provide methods. Use ECS systems or EntityManager APIs to read/write it.
Usage Example
using Unity.Entities;
using Game.Prefabs;
// Add the component to an existing entity (e.g., a prefab entity)
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity meshEntity = /* obtain or create the mesh entity */;
Entity prefabEntity = /* prefab entity to attach to */;
var shared = new SharedMeshData { m_Mesh = meshEntity };
entityManager.AddComponentData(prefabEntity, shared);
// Read in a SystemBase
public partial class SharedMeshSystem : SystemBase
{
protected override void OnUpdate()
{
Entities
.ForEach((in SharedMeshData shared) =>
{
Entity mesh = shared.m_Mesh;
if (mesh != Entity.Null)
{
// use mesh Entity (lookup components, schedule jobs, etc.)
}
})
.Schedule();
}
}
{{ Notes: This struct is intended for DOTS usage. Ensure you include Unity.Entities and that your project's Entities package version supports IQueryTypeParameter as used above. Validate that the mesh entity you reference is valid for the lifetime you expect (avoid stale references). }}