Skip to content

Game.TimeSettingsData

Assembly:
Assembly-CSharp

Namespace: Game.Prefabs

Type:
struct

Base:
Implements Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter

Summary:
A small ECS component that stores the number of days per year used by the game's time system. This plain data component is meant to be attached to an entity (for example a global settings/prefab entity) so systems can read or modify the current days-per-year value. Because it is an IComponentData value type it is cheap to add/remove and to read from jobs and systems; because it implements IQueryTypeParameter it can be referenced in queries when appropriate.


Fields

  • public int m_DaysPerYear
    Number of days in a year used by the game time system. Expected to be a positive integer (commonly 365, 360, etc.). Changing this value at runtime will affect any systems that compute seasonal or yearly progression — ensure systems that cache or precompute time-dependent values respond to updates.

  • private System.Diagnostics.Stopwatch m_Stopwatch
    This component does not contain a Stopwatch; no private stopwatch field exists in this struct. (Included in the template for reference; ignore if not present.)

  • private Unity.Jobs.JobHandle <producerHandle>k__BackingField
    This component does not contain a JobHandle backing field; no producerHandle backing field exists in this struct. (Included in the template for reference; ignore if not present.)

Properties

  • public Unity.Jobs.JobHandle producerHandle { get; private set }
    No properties are defined on this struct. Access the data directly via the public field m_DaysPerYear when reading/writing from systems.

Constructors

  • public TimeSettingsData()
    The compiler-provided default constructor initializes the value to 0. For meaningful runtime behavior you should assign a positive integer (e.g., 365) when creating the component.

(You may also create and use an explicit constructor if desired:)

public TimeSettingsData(int daysPerYear)
{
    m_DaysPerYear = daysPerYear;
}

Methods

  • protected virtual OnCreate() : System.Void
    This struct defines no methods. Component lifecycle and setup are handled by systems or authoring components that create/add this component on entities.

Usage Example

// Add the component to an entity (one-time setup)
var settings = new TimeSettingsData { m_DaysPerYear = 365 };
entityManager.AddComponentData(settingsEntity, settings);

// Read/update in a SystemBase
public partial class TimeSettingsSystem : SystemBase
{
    protected override void OnUpdate()
    {
        // Read-only example: read current days-per-year
        Entities
            .WithName("ReadTimeSettings")
            .ForEach((in TimeSettingsData timeSettings) =>
            {
                int days = timeSettings.m_DaysPerYear;
                // use days in calculations...
            }).Run();

        // Update example: change days-per-year via EntityManager or ECB
        var ecb = new EntityCommandBuffer(Allocator.Temp);
        Entities.ForEach((Entity e, ref TimeSettingsData ts) =>
        {
            ts.m_DaysPerYear = 360; // set a new value
        }).Run();
    }
}

Notes and recommendations: - Validate values (m_DaysPerYear > 0) before applying; unexpected values may break time calculations. - If multiple systems cache year-length-dependent data, ensure they respond to changes (e.g., by listening for component changes or using change filters). - Prefer using EntityCommandBuffer when modifying components from jobs or multi-threaded contexts. - For modders exposing user-configurable time settings, consider exposing a MonoBehaviour authoring component that writes this component onto a dedicated settings entity at startup.