Skip to content

Game.Prefabs.Effect

Assembly: Assembly-CSharp (typical for Cities: Skylines 2 mods; adjust if different)
Namespace: Game.Prefabs

Type: struct

Base: Unity.Entities.IBufferElementData

Summary:
Represents a per-entity dynamic buffer element describing a visual/audio effect instance. This buffer element stores the effect entity reference and transformation/attachment data used by effect systems (position, scale, rotation), animation/bone attachment info, intensity, and flags for procedural effects. The struct is marked with [InternalBufferCapacity(0)], meaning the buffer has no inline storage on the entity and uses a heap allocation for elements.


Fields

  • public Unity.Entities.Entity m_Effect
    Reference to the effect entity/prefab instance to spawn or drive. This is typically an Entity pointing to a prefab or effect archetype.

  • public Unity.Mathematics.float3 m_Position
    Local or world position for the effect instance. Semantics (local vs world) depend on the system consuming this buffer; when attached to a parent, this is commonly a local offset.

  • public Unity.Mathematics.float3 m_Scale
    Scale of the effect instance as a float3.

  • public Unity.Mathematics.quaternion m_Rotation
    Rotation of the effect instance expressed as a quaternion.

  • public Unity.Mathematics.int2 m_BoneIndex
    Two-component integer vector used for bone/attachment indexing. Often used to encode primary and secondary bone indices (or bone index and sub-index) when attaching effects to skinned meshes.

  • public float m_Intensity
    A multiplier or strength parameter for the effect (e.g., particle spawn rate, light intensity, sound volume). Interpretation depends on effect implementation.

  • public int m_ParentMesh
    Index or identifier for the parent mesh or sub-mesh this effect is attached to. Used by systems that map buffer entries to specific renderable mesh parts.

  • public int m_AnimationIndex
    Index of an animation or animation state that the effect should follow or synchronize with.

  • public bool m_Procedural
    Flag indicating whether the effect is procedural (generated at runtime) rather than a baked/prefab-driven effect. Systems may treat procedural effects differently (e.g., skip prefab instantiation and run a generator).

Properties

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

Constructors

  • public Effect()
    Implicit default constructor provided by C#. Fields will be default-initialized (Entity = Entity.Null, numeric values = 0, quaternion = (0,0,0,0) unless set otherwise). No explicit constructor is defined in the source.

Methods

  • None (no methods are defined on this struct).

Usage Example

// Example: adding an Effect element to an entity's DynamicBuffer
using Unity.Entities;
using Unity.Mathematics;

public static void AddEffectToEntity(EntityManager em, Entity targetEntity, Entity effectPrefab)
{
    // Ensure the entity has a DynamicBuffer<Effect> (adds a buffer component if missing)
    if (!em.HasComponent<Effect>(targetEntity))
    {
        em.AddBuffer<Effect>(targetEntity);
    }

    var buffer = em.GetBuffer<Effect>(targetEntity);

    Effect e = new Effect
    {
        m_Effect = effectPrefab,
        m_Position = new float3(0f, 1.0f, 0f),
        m_Scale = new float3(1f, 1f, 1f),
        m_Rotation = quaternion.EulerXYZ(new float3(0f, 0f, 0f)),
        m_BoneIndex = new int2(0, -1),
        m_Intensity = 1.0f,
        m_ParentMesh = 0,
        m_AnimationIndex = 0,
        m_Procedural = false
    };

    buffer.Add(e);
}

Notes: - Because [InternalBufferCapacity(0)] is used, the buffer has no inline storage on the entity; expect heap allocations when elements are added. - Interpretations of fields like m_Position (local vs world), m_BoneIndex, m_ParentMesh, and m_AnimationIndex depend on the systems that consume this buffer — check the corresponding effect/spawn systems in the codebase to ensure correct values.