Skip to content

Game.Prefabs.HappinessFactorParameterData

Assembly: Assembly-CSharp (game assembly)

Namespace: Game.Prefabs

Type: struct

Base: Unity.Entities.IBufferElementData

Summary:
A small ECS buffer element that stores parameters used to modify or track a happiness factor for prefabs/entities. Each element carries an integer base level and an optional Entity reference (m_LockedEntity) that can be used to lock or associate the happiness parameter with a specific entity (set to Entity.Null when unused). This struct is intended to be used in DynamicBuffer on entities that need one-or-many happiness-related parameters.


Fields

  • public int m_BaseLevel
    An integer representing the base happiness level or modifier for this parameter entry. Interpretation (absolute value, delta, priority, etc.) depends on the systems that consume this buffer element.

  • public Unity.Entities.Entity m_LockedEntity
    An Entity reference associated with this happiness parameter. Common uses:

  • link the parameter to another entity (e.g., a building, citizen, or object),
  • indicate the parameter is locked by a particular entity,
  • set to Entity.Null when there is no associated entity.

Properties

  • This type has no properties. It only exposes the public fields above.

Constructors

  • public HappinessFactorParameterData()
    The default value-type constructor is provided implicitly. Default field values:
  • m_BaseLevel == 0
  • m_LockedEntity == Entity.Null

Methods

  • This type defines no methods. It is a plain buffer element data struct used with DynamicBuffer.

Usage Example

// Create an entity with a buffer of HappinessFactorParameterData
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var archetype = entityManager.CreateArchetype(typeof(HappinessFactorParameterData));
Entity e = entityManager.CreateEntity(archetype);

// Add entries to the buffer
var buffer = entityManager.GetBuffer<HappinessFactorParameterData>(e);
buffer.Add(new HappinessFactorParameterData { m_BaseLevel = 10, m_LockedEntity = Entity.Null });
buffer.Add(new HappinessFactorParameterData { m_BaseLevel = -5, m_LockedEntity = someOtherEntity });

// Reading the buffer inside a SystemBase
protected override void OnUpdate()
{
    Entities
        .ForEach((in DynamicBuffer<HappinessFactorParameterData> happinessBuffer) =>
        {
            foreach (var item in happinessBuffer)
            {
                // Use item.m_BaseLevel and item.m_LockedEntity
            }
        })
        .WithoutBurst()
        .Run();
}

{{ Notes: Use Entity.Null for no association. This struct is blittable and safe to use in Jobs when accessed via DynamicBuffer. If you need a fixed capacity buffer on the entity archetype, consider using InternalBufferCapacity attribute on the buffer element (on definition) or ensure archetype includes it as needed. }}