Skip to content

Game.Prefabs.ProceduralBone

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: struct

Base: Unity.Entities.IBufferElementData

Summary:
Represents a single procedural bone entry stored in an ECS dynamic buffer. This buffer element contains transform data (local and object space), bind pose, hierarchy and connection metadata, and simple dynamics (speed/acceleration). It's intended for use with prefabs or runtime-generated skeletons/rigs in Cities: Skylines 2 mod code that uses Unity.Entities and Unity.Mathematics. The type is annotated with [InternalBufferCapacity(0)], so no inline capacity is reserved on the entity (the buffer is stored on the heap).


Fields

  • public float3 m_Position
    Local position of the bone in object (or bone-local) space.

  • public float3 m_ObjectPosition
    Position of the bone in object/world space (depending on convention used by the system). Typically used to store the transformed/accumulated position.

  • public quaternion m_Rotation
    Local rotation of the bone as a quaternion.

  • public quaternion m_ObjectRotation
    Rotation of the bone in object/world space (accumulated rotation).

  • public float3 m_Scale
    Local scale of the bone.

  • public float4x4 m_BindPose
    Bind pose matrix for the bone (4x4 matrix). Used for skinning or to return a bone to its rest pose relative to the mesh.

  • public BoneType m_Type
    An enum value indicating the bone classification (e.g., joint, helper, connection). BoneType is not defined here but expected elsewhere in the codebase.

  • public int m_ParentIndex
    Index of the parent bone within the same buffer (or -1 if none). Useful for hierarchical traversal.

  • public int m_BindIndex
    Index used for binding to mesh bone indices (e.g., mapping to a skinned mesh bone array).

  • public int m_HierarchyDepth
    Depth of the bone in the hierarchy (root = 0). Can be used for ordered updates.

  • public int m_ConnectionID
    Identifier for a connection point or joint pairing (semantic meaning depends on the system).

  • public int m_SourceIndex
    Source index referencing an origin bone or source data (used for mapping or synchronization).

  • public float m_Speed
    Scalar representing speed for procedural motion/animation for this bone.

  • public float m_Acceleration
    Scalar representing acceleration used by procedural simulation.

Properties

  • None (this is a plain IBufferElementData struct exposing public fields).

Additional notes: The [InternalBufferCapacity(0)] attribute is applied to the struct, indicating no inline buffer capacity reservation on the entity.

Constructors

  • public ProceduralBone()
    No custom constructor is defined. This is a value type (struct), so a default parameterless constructor is provided by the runtime and all fields are default-initialized. Typical creation is via DynamicBuffer.Add or by setting fields directly.

Methods

  • None (no methods defined on this struct).

Usage Example

// Example: creating an entity with a ProceduralBone buffer and adding a bone entry
using Unity.Entities;
using Unity.Mathematics;

public class ProceduralBoneExample : SystemBase
{
    protected override void OnCreate()
    {
        base.OnCreate();
    }

    protected override void OnUpdate()
    {
        var em = World.DefaultGameObjectInjectionWorld.EntityManager;

        // Create an entity with no components, then add the buffer
        var entity = em.CreateEntity();
        var boneBuffer = em.AddBuffer<Game.Prefabs.ProceduralBone>(entity);

        // Add a bone to the buffer
        boneBuffer.Add(new Game.Prefabs.ProceduralBone
        {
            m_Position = new float3(0f, 0f, 0f),
            m_ObjectPosition = new float3(0f, 0f, 0f),
            m_Rotation = quaternion.identity,
            m_ObjectRotation = quaternion.identity,
            m_Scale = new float3(1f, 1f, 1f),
            m_BindPose = float4x4.identity,
            m_Type = BoneType.Default, // replace with an actual enum member from your codebase
            m_ParentIndex = -1,
            m_BindIndex = 0,
            m_HierarchyDepth = 0,
            m_ConnectionID = 0,
            m_SourceIndex = 0,
            m_Speed = 0f,
            m_Acceleration = 0f
        });

        // Read/update the buffer later:
        var readBuffer = em.GetBuffer<Game.Prefabs.ProceduralBone>(entity);
        var firstBone = readBuffer[0];
        // modify
        firstBone.m_Position += new float3(0f, 0.1f, 0f);
        readBuffer[0] = firstBone;
    }
}

Notes: - Replace BoneType.Default with the appropriate enum value defined in your project. - Because this is an IBufferElementData, access should be done via DynamicBuffer in systems for best performance. - Use hierarchy indices and parent indices to traverse the bone tree in update systems (top-down or bottom-up depending on your algorithm).