Wiki

trigger · count_in_collection

Definition

  • Supported scope:COUNTRY
  • Supported target:none

Description

Checks the size of a given collection.
	Note: unit and building and manpower are mutually exclusive

	### Example
	```
	count_in_collection = {
		collection = {
			input = game:scope
			operators = { faction_members }
			name = FACTION
		}
		unit = armor  # (optional) checks the number of subunits that have the correct equipment type
		buildings = {industrial_complex } # (optional) checks the number of building types in total
		manpower = yes # (optional, default: no) checks the number of deployed manpower
		equipment_ratio = 0.9 (optional, only works with land units default 0) what percentage of equipment the division needs to atleast have to be counted
		unit_category = { marine marine_commando category_fighter }(optional) checks the number of sub units that match a certain sub unit definition / category
		stockpile = light_tank_equipment (optional) counts the amount of a certain archetype in the countries stockpile
		size > 10
	}
	```

Hands-On Notes

Hands-on notes are AI-generated and checked against the vanilla command vocabulary — treat them as a starting point, not authoritative reference. The definition above is the game's own documentation.

Hands-On Usage

count_in_collection is commonly used to detect the number of faction members, units of a certain type, or the scale of deployed forces, thereby dynamically unlocking decisions, triggering events, or restricting national focuses. For example, you can use it to determine whether the faction that the player belongs to has reached a certain scale before allowing a "unified action" decision to appear:

available = {
    count_in_collection = {
        collection = {
            input = game:scope
            operators = { faction_members }
            name = FACTION
        }
        size > 4
    }
}

Synergy

  • [any_faction_member](/wiki/trigger/any_faction_member) / [all_faction_member](/wiki/trigger/all_faction_member) (not in the whitelist, but can reference those in the whitelist) → Use in conjunction with [has_completed_focus](/wiki/trigger/has_completed_focus): first use count_in_collection to confirm that the faction scale meets the threshold, then use this trigger to check whether members have completed a specific national focus. Together, they form a more precise condition gate.
  • [add_faction_goal](/wiki/effect/add_faction_goal): typically only append new goals to the faction after count_in_collection confirms that the faction member count meets the requirements, avoiding triggering invalid logic when the faction scale is insufficient.
  • [faction_influence_ratio](/wiki/trigger/faction_influence_ratio): when combined with count_in_collection, both the "scale" and "influence ratio" of the faction can be constrained simultaneously. This dual filtering ensures that only truly dominant major factions can trigger specific narrative events.
  • [activate_targeted_decision](/wiki/effect/activate_targeted_decision): once count_in_collection passes the judgment, use this effect to batch activate targeted decisions against faction members, implementing a linked mechanism that triggers when the scale threshold is met.

Common Pitfalls

  1. unit, buildings, manpower are mutually exclusive (choose one): beginners often write multiple filter fields simultaneously (such as writing both unit = armor and manpower = yes), which causes script errors or undefined behavior. You must keep only one of them, or write none of the three (in which case the count is the number of elements in the collection itself).
  2. operators in collection is written incorrectly, resulting in an empty set: operators determines how the set is expanded from the input scope. If you use operators that are not applicable to the current scope (for example, using faction_members under a non-faction country scope), the collection returns an empty set and size > 0 is always false. However, the script will not report an error, making it extremely difficult to debug.