Skip to content

Game.Objects.TransformFrame

Assembly: Assembly-CSharp
Namespace: Game.Objects

Type: struct

Base: System.ValueType, Unity.Entities.IBufferElementData, Colossal.Serialization.Entities.ISerializable

Summary:
A lightweight ECS buffer element that represents a single snapshot/frame of an object's transform and small state metadata. Marked with InternalBufferCapacity(4) so the default per-entity buffer allocation is 4 elements. Used to store positional, rotational and simple state information (including velocity and activity/state timers) for interpolation, movement history or state replication. The struct implements a custom (de)serialization that only writes/reads the compact state fields (state timer, state enum and activity), not the full transform, to keep persisted/replicated payloads small.


Fields

  • public Unity.Mathematics.float3 m_Position
    Position for this frame (world-space). Used for interpolation/rewinding.

  • public Unity.Mathematics.float3 m_Velocity
    Linear velocity for this frame. Populated by constructors that accept a Moving value.

  • public Unity.Mathematics.quaternion m_Rotation
    Rotation for this frame (world-space).

  • public TransformFlags m_Flags
    Bitfield flags for additional transform-related flags (implementation-defined).

  • public System.UInt16 m_StateTimer
    Small timer/counter associated with m_State (e.g., remaining ticks or elapsed frames).

  • public TransformState m_State
    Enumerated state for the transform (custom TransformState enum). Serialized as a single byte.

  • public System.Byte m_Activity
    Activity byte (packed flags or small activity index), serialized as a single byte.

Properties

  • None

Constructors

  • public TransformFrame(Transform transform)
    Creates a frame from a Transform. Sets position and rotation from the Transform; velocity is zero and state/flags/activity are initialized to defaults.

  • public TransformFrame(Transform transform, Moving moving)
    Creates a frame from a Transform and a Moving component. Position and rotation come from transform; velocity is taken from Moving.m_Velocity. State/flags/activity are initialized to defaults.

  • public TransformFrame(Unity.Mathematics.float3 position, Unity.Mathematics.quaternion rotation, Unity.Mathematics.float3 velocity)
    Creates a frame from explicit position, rotation and velocity values. State/flags/activity are initialized to defaults.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes a compact representation of the frame's state to the supplied writer. The implementation writes, in order: m_StateTimer (ushort), m_State (as a single byte), and m_Activity (byte). Note: position, rotation, velocity and flags are intentionally not serialized by this method.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the compact state representation from the supplied reader, restoring m_StateTimer, m_State (read as a byte and cast to TransformState) and m_Activity. Position/rotation/velocity/flags are not read by this method and must be set by other means if needed.

Usage Example

// Example: creating frames and adding them into an ECS dynamic buffer
EntityManager em = ...;
Entity entity = ...;

// get or create a DynamicBuffer<TransformFrame> for the entity
var buffer = em.GetBuffer<TransformFrame>(entity);

// create frames from a Transform / Moving components (types are game-specific)
Transform t = /* obtain transform */;
Moving m = /* obtain moving */;
var frame1 = new TransformFrame(t);               // velocity zero
var frame2 = new TransformFrame(t, m);            // uses moving.m_Velocity
var frame3 = new TransformFrame(t.m_Position, t.m_Rotation, m.m_Velocity);

// push frames into the buffer
buffer.Add(frame1);
buffer.Add(frame2);
buffer.Add(frame3);

Additional notes: - The field attribute [InternalBufferCapacity(4)] sets the default inline capacity of the DynamicBuffer to 4 elements before an extra heap allocation is required. - The custom serialization focuses on compact state data; if you need to persist or network full transform data, you will need to extend the serialization logic to include position/rotation/velocity/flags.