Skip to content

Game.LocalTransformCache

Assembly: Assembly-CSharp (typical for Unity mods)
Namespace: Game.Tools

Type: struct

Base: IComponentData, IQueryTypeParameter

Summary:
A small, blittable component that caches per-entity local transform and placement metadata used by game tooling/systems (for example: procedural placement, prefab selection, or batching). Stores position and rotation (as local-space values) plus several integer indices/weights used to select parent mesh, group/variant, and probability/sub-index information. Designed to be used directly in ECS queries, jobs, and Burst-compiled systems.


Fields

  • public float3 m_Position
    Local position (float3). Interpreted in the local coordinate space for the entity (typically meters). Used to drive Translation/LocalToParent/LocalToWorld as needed.

  • public quaternion m_Rotation
    Local rotation (quaternion). Used to drive Rotation/LocalToParent orientation.

  • public int m_ParentMesh
    Index or identifier referencing the parent mesh or parent instance. Conventionally used as an index into a separate mesh/parent lookup table. A sentinel value such as -1 typically indicates "no parent" (implementation-specific).

  • public int m_GroupIndex
    Grouping index for variant selection, LOD grouping, or other classification. Used by systems that pick a group of prefabs or batching groups.

  • public int m_Probability
    An integer weight or probability value used when selecting variants at spawn/placement time. Interpretation (e.g., 0–100 vs arbitrary weight) depends on the consuming system.

  • public int m_PrefabSubIndex
    Index of the sub-prefab or sub-variant within a prefab/group. Used to pick a specific model/variant from a parent prefab.

Properties

  • This struct exposes no properties. All data is stored in public fields to keep the component blittable and efficient for ECS/job access.

Constructors

  • public LocalTransformCache()
    No explicit constructors are defined. The default parameterless struct constructor initializes all numeric fields to zero (m_Position = float3.zero, m_Rotation = quaternion.identity if explicitly set later; otherwise all fields are zeroed). Consumers should set meaningful values before use.

Methods

  • This type contains no methods. It is plain data intended to be read/written by ECS systems and jobs. Because it implements IComponentData and IQueryTypeParameter it can be used directly in Entities.ForEach, ComponentSystem, SystemBase queries, and Burst jobs.

Usage Example

using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using Game.Tools;

// Create an entity and attach LocalTransformCache
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
var archetype = em.CreateArchetype(typeof(LocalTransformCache), typeof(Translation), typeof(Rotation));
var entity = em.CreateEntity(archetype);

em.SetComponentData(entity, new LocalTransformCache {
    m_Position = new float3(1f, 0f, 2f),
    m_Rotation = quaternion.identity,
    m_ParentMesh = -1,
    m_GroupIndex = 0,
    m_Probability = 100,
    m_PrefabSubIndex = 0
});

// SystemBase example that applies the cached transform to Translation/Rotation
public partial class ApplyLocalTransformSystem : SystemBase
{
    protected override void OnUpdate()
    {
        Entities
            .ForEach((ref Translation t, ref Rotation r, in LocalTransformCache cache) =>
            {
                t.Value = cache.m_Position;
                r.Value = cache.m_Rotation;
            })
            .ScheduleParallel();
    }
}

Notes: - Because LocalTransformCache is a blittable IComponentData, it is suitable for use in Burst-compiled jobs and high-performance ECS code. - Field semantics such as sentinel values and probability range are determined by the consuming game systems; consult the modding API or consuming systems for exact conventions.