Game.Prefabs.HouseholdPrefab
Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs
Type: class
Base: ArchetypePrefab
Summary:
Prefab class that defines household archetypes used to spawn household entities (citizens/families) in the simulation. Exposes configuration for initial composition (children, adults, elderly, students), initial wealth/car probabilities, pet probabilities, and whether the household is dynamic (used for split/divorce/move-out households). During initialization this prefab writes a HouseholdData component onto the entity and optionally marks it as a DynamicHousehold.
Fields
-
public int m_ResourceConsumption
Controls resource consumption level for the household (used by economy/resource systems). Default not specified in source (0 if unset). -
public int m_InitialWealthRange
Range used when assigning initial wealth to the household (together with m_InitialWealthOffset). -
public int m_InitialWealthOffset
Offset added to wealth when calculating initial household wealth. -
public int m_InitialCarProbability
Percentage chance of the household arriving with a car. Shown with a Tooltip in the inspector. -
public int m_ChildCount
Number of children in the household. -
public int m_AdultCount
Number of adults in the household. -
public int m_ElderlyCount
Number of elderly members in the household. -
public int m_StudentCount
Number of guaranteed students in the household (guaranteed to be college/uni age and have education level 2). Has a Tooltip in the inspector. -
public int m_FirstPetProbability = 20
Probability (percentage) for the household to have the first pet. Default = 20. -
public int m_NextPetProbability = 10
Probability (percentage) for subsequent pets. Default = 10. -
public bool m_DynamicHousehold
Indicates the prefab is intended for dynamic households (created when e.g., kids move out or a divorce occurs). Those households do not require random citizens to be generated. Tooltip present in inspector. -
public int m_Weight = 1
Weight used when selecting this prefab among multiple options (higher = more likely). Default = 1.
Properties
- (none declared in this class)
All configuration is exposed as public fields. The prefab writes a HouseholdData component at initialization for runtime use.
Constructors
public HouseholdPrefab()
Implicit default constructor. The prefab is typically instantiated by Unity ( inspector / asset system ), so no custom constructor logic is defined here.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds components required on the prefab-level entity. This method:- Calls base implementation.
- Adds HouseholdData (ReadWrite).
-
If m_DynamicHousehold is true, also adds DynamicHousehold (ReadWrite).
-
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds runtime archetype components that will be present on spawned household entities. This method: - Calls base implementation.
-
Adds Household, HouseholdNeed, HouseholdCitizen, TaxPayer, Game.Economy.Resources, PropertySeeker, and UpdateFrame (all ReadWrite).
-
public override void Initialize(EntityManager entityManager, Entity entity)
Writes initial HouseholdData onto the created entity using the prefab's public field values. Specifically it sets: - m_InitialCarProbability
- m_InitialWealthOffset
- m_InitialWealthRange
- m_ChildCount
- m_AdultCount
- m_ElderCount (note: field name in component is m_ElderCount, assigned from m_ElderlyCount)
- m_StudentCount
- m_FirstPetProbability
- m_NextPetProbability
- m_Weight
This is the place the prefab transfers inspector-configured values into the ECS component used at runtime.
Usage Example
// Typical override used by the prefab system to initialize the entity's components
public override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
// The prefab sets a HouseholdData component based on the inspector fields:
entityManager.SetComponentData(entity, new HouseholdData
{
m_InitialCarProbability = m_InitialCarProbability,
m_InitialWealthOffset = m_InitialWealthOffset,
m_InitialWealthRange = m_InitialWealthRange,
m_ChildCount = m_ChildCount,
m_AdultCount = m_AdultCount,
m_ElderCount = m_ElderlyCount,
m_StudentCount = m_StudentCount,
m_FirstPetProbability = m_FirstPetProbability,
m_NextPetProbability = m_NextPetProbability,
m_Weight = m_Weight
});
}
{{ Additional notes - Use m_DynamicHousehold when creating small households that should not get randomized citizen data (e.g., after family splits). - The prefab only configures HouseholdData and the archetype; the simulation systems create/assign actual Citizen entities based on the Household and HouseholdCitizen archetype components. - Be careful with m_ElderlyCount -> m_ElderCount mapping: the component field name differs slightly and is mapped during Initialize. }}