Skip to content

Game.Prefabs.SwayingData

Assembly:
(assembly not specified in source; typically this type is compiled into the game's main assembly, e.g., Assembly-CSharp)

Namespace: Game.Prefabs

Type: struct

Base: System.ValueType, Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter

Summary:
SwayingData is a plain ECS component (struct) that stores per-entity parameters used to drive a swaying/soft-body motion simulation. It exposes per-axis factors for velocity influence, spring strength, damping, and maximum allowed position offset. Intended to be attached to entities that require procedural swaying behavior (for example foliage, hanging objects, or decorations) and read by a system that performs the sway simulation each frame.


Fields

  • public float3 m_VelocityFactors
    Holds per-axis multipliers applied to the object's current velocity when computing swaying response. Typical use: scale how much the object's world velocity contributes to displacement along x, y, z.

  • public float3 m_SpringFactors
    Per-axis spring stiffness values used to pull the object back toward its rest position. Higher values produce faster return and a "stiffer" feel.

  • public float3 m_DampingFactors
    Per-axis damping coefficients that reduce oscillation over time. Higher damping reduces oscillation amplitude and causes faster settling.

  • public float3 m_MaxPosition
    Per-axis maximum allowed position offset from the rest position. Used to clamp displacement so the object doesn't sway beyond reasonable bounds.

Properties

  • None (this is a simple public-field struct with no properties)

Constructors

  • public SwayingData() (implicit default)
    Struct has the implicit default constructor generated by C#. Initialize fields manually or with an object initializer to desired default values.

Methods

  • None (no methods defined on this struct)

Usage Example

using Unity.Entities;
using Unity.Mathematics;
using Game.Prefabs;

// Create and initialize a SwayingData instance
var sway = new SwayingData
{
    m_VelocityFactors = new float3(0.5f, 0.3f, 0.5f),
    m_SpringFactors   = new float3(8f, 6f, 8f),
    m_DampingFactors  = new float3(1.5f, 1.2f, 1.5f),
    m_MaxPosition     = new float3(0.25f, 0.25f, 0.25f)
};

// Add to an existing entity (EntityManager context assumed)
EntityManager.AddComponentData(someEntity, sway);

// Example: query in a system (IQueryTypeParameter support allows using the type in queries)
public partial class SwaySystem : SystemBase
{
    protected override void OnUpdate()
    {
        float deltaTime = Time.DeltaTime;
        Entities
            .ForEach((ref Translation t, in SwayingData sway) =>
            {
                // read sway fields and apply simulation per entity
                // (actual simulation logic depends on how velocity, springs and damping are modeled)
            })
            .ScheduleParallel();
    }
}

Notes: - Values are per-axis (X, Y, Z) using Unity.Mathematics.float3. - This component only carries parameters; the runtime simulation typically requires additional component state (e.g., current displacement, velocity) stored elsewhere. - Because SwayingData implements IQueryTypeParameter, it can be used to shape/optimize ECS queries in contexts where that pattern is supported.