Skip to content

Game.Rendering.Swaying

Assembly:
{{ Likely part of the game's main assembly (Game). If you keep your mod in a separate assembly, reference the assembly that contains this type. }}

Namespace: Game.Rendering

Type:
struct (IComponentData, IQueryTypeParameter, IEmptySerializable)

Base:
System.ValueType

Summary:
{{ Swaying is a small ECS component used to store per-entity swaying state for rendering (for example, subtle motion caused by wind or inertia). It uses Unity.Mathematics.float3 for compact vector storage and is designed to be used with Unity's ECS (DOTS) and the game's Colossal serialization pipeline. Because it implements IComponentData it can be attached to entities and used inside Jobs/Systems; IEmptySerializable / IQueryTypeParameter indicate integration with the game's/custom serialization and query patterns. }}


Fields

  • public Unity.Mathematics.float3 m_LastVelocity
    {{ The entity's previous-frame velocity used as a reference when computing sway. Typically used to compute velocity changes that drive sway motion. }}

  • public Unity.Mathematics.float3 m_SwayPosition
    {{ The current sway offset position (local offset applied for rendering). This is the positional component of the sway effect. }}

  • public Unity.Mathematics.float3 m_SwayVelocity
    {{ The current velocity of the sway (rate of change of m_SwayPosition). Used when integrating sway over time or damping it. }}

Properties

{{ This struct defines no C# properties. Use its public fields directly when reading/writing component data. }}

Constructors

  • public Swaying()
    {{ As a value type, Swaying has the implicit default constructor which initializes all float3 fields to float3.zero. If you need non-zero defaults, construct explicitly with field initializers when adding the component. }}

Methods

  • None
    {{ There are no methods defined on this component. Any behavior (integration, damping, applying to transforms) should be implemented in Systems or Jobs that read/write this component. }}

Usage Example

// Example: Add and initialize Swaying on an entity
var sway = new Game.Rendering.Swaying {
    m_LastVelocity = float3.zero,
    m_SwayPosition = float3.zero,
    m_SwayVelocity = float3.zero
};
entityManager.AddComponentData(entity, sway);

// Example: Simple SystemBase job to integrate sway (conceptual)
public partial class SwayIntegrationSystem : SystemBase
{
    protected override void OnUpdate()
    {
        float dt = Time.DeltaTime;
        Entities.ForEach((ref Game.Rendering.Swaying sway, in PhysicsVelocity velocity) =>
        {
            // compute velocity difference
            float3 velDelta = velocity.Linear - sway.m_LastVelocity;

            // drive sway velocity from acceleration (simple example)
            sway.m_SwayVelocity += velDelta * 0.5f;

            // integrate position with damping
            sway.m_SwayPosition += sway.m_SwayVelocity * dt;
            sway.m_SwayVelocity *= math.exp(-1.5f * dt); // damping

            // store last velocity for next frame
            sway.m_LastVelocity = velocity.Linear;
        }).ScheduleParallel();
    }
}

{{ Notes: - Use Unity.Mathematics.float3 (namespace Unity.Mathematics) for vector math. - Because Swaying is an IComponentData it is blittable and safe to use in Jobs. - The component is minimal and intended to be used by rendering/animation systems that convert the sway state into transform offsets for visuals. - If you rely on serialization from Colossal.Serialization, the presence of IEmptySerializable indicates compatibility with the game's serialization infrastructure — ensure your mod's serializer registration matches the game's expectations. }}