Skip to content

Game.Prefabs.OutsideConnection

Assembly: Game
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
OutsideConnection is a prefab Component that represents an outside connection point (for trade/commuting) in Cities: Skylines 2. It exposes editor-configurable fields for the resources traded, whether commuting is enabled, the transfer type, and a remoteness value. The prefab registers the required ECS prefab and archetype components (storage, transport company, trade-related components, etc.) and initializes entity component data (OutsideConnectionData, StorageCompanyData and TransportCompanyData) when the prefab is instantiated. The class is exposed in the component menu under "Objects/" alongside StaticObjectPrefab and MarkerObjectPrefab.


Fields

  • public ResourceInEditor[] m_TradedResources
    List of resources configured in the editor that this outside connection can trade. During initialization these are converted (via EconomyUtils.GetResource) into a Resource bitmask stored in the StorageCompanyData component.

  • public bool m_Commuting
    Flag indicating whether the connection supports commuting. (Used by game systems that handle citizen trips; the value is stored on the prefab but this class does not directly write a commuting component.)

  • public OutsideConnectionTransferType m_TransferType
    Transfer type for the outside connection (e.g., import/export/other transfer semantics). This value is written into the OutsideConnectionData component during initialization.

  • public float m_Remoteness
    Remoteness value that affects trade/behavior; copied into OutsideConnectionData during initialization.

Properties

  • None declared on this class. All configuration is exposed via public fields.

Constructors

  • public OutsideConnection()
    Default constructor (inherited behavior). Prefab instances are typically configured in the editor; no custom constructor logic is defined.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds component types required for the prefab instance to the provided set. This method registers the prefab-level component data types the entity will contain:
  • OutsideConnectionData (Read/Write)
  • StorageCompanyData (Read/Write)
  • TransportCompanyData (Read/Write)

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds component types required for the ECS archetype when this prefab is instantiated. The method registers runtime components that will be present on created entities, for example:

  • Game.Objects.OutsideConnection
  • Resources
  • Game.Companies.StorageCompany
  • TradeCost
  • StorageTransferRequest
  • TripNeeded
  • ResourceSeller
  • TransportCompany
  • OwnedVehicle

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Initializes component data on the created entity:

  • Writes an OutsideConnectionData instance with m_Type set from prefab.m_TransferType and m_Remoteness set from prefab.m_Remoteness.
  • Builds a StorageCompanyData where m_StoredResources is initialized to Resource.NoResource and then OR'd with EconomyUtils.GetResource(...) for each entry in m_TradedResources (if any) to form a resource bitmask. This is written to the entity.
  • Writes a TransportCompanyData with m_MaxTransports = int.MaxValue (effectively allowing unlimited transport registrations from this connection).
  • Uses EntityManager.SetComponentData to apply these component data objects to the entity.

Notes: - The class relies on EconomyUtils.GetResource to translate editor ResourceInEditor entries into the internal Resource bitmask. - m_Commuting is exposed but not directly written into a specific component in this method; commuting handling is handled by other systems that read this prefab data or by other components added elsewhere.

Usage Example

// Pseudocode showing how a prefab might be used by the prefab system.
// Prefab instances are normally instantiated by the game's prefab manager; manual usage:
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity entity = entityManager.CreateEntity(); // the archetype would be created by the prefab system

// Assume `outsidePrefab` is a reference to a configured OutsideConnection prefab instance (from assets)
OutsideConnection outsidePrefab = /* obtain prefab reference from assets/prefab manager */;

// The prefab initialize method configures the entity's component data (OutsideConnectionData, StorageCompanyData, TransportCompanyData)
outsidePrefab.Initialize(entityManager, entity);

{{ Additional information: - This prefab class is decorated with [ComponentMenu("Objects/", typeof(StaticObjectPrefab), typeof(MarkerObjectPrefab))], making it selectable in the editor under Objects. - The StorageCompanyData.m_StoredResources value is a bitmask of internal Resource enum values; ensure ResourceInEditor entries correspond to valid EconomyUtils.GetResource mappings. - TransportCompanyData.m_MaxTransports is set to int.MaxValue here to indicate no practical limit on transports originating from this connection. }}