Summary
Custom NPCs currently cannot declare their designated map region through NPCPrefabBuilder during ConfigurePrefab.
Setting NPC.Region later from OnCreated() can be too late for native initialization. The base game's NPCRelationData.Init(NPC) validates every relationship connection against the owning NPC's region and removes connections whose regions differ.
Observed behavior
A custom Uptown supplier configured with connections to Herbert Bleuball and Tobias Wentworth sets:
- the connections through
WithRelationshipDefaults(...WithConnections<...>()) during ConfigurePrefab
Region = Region.Uptown during OnCreated()
During native relationship initialization, the custom NPC can still carry its inherited/default region. The game then logs:
NPC Herbert is in a different region than Disco. Removing connection.
NPC Tobias is in a different region than Disco. Removing connection.
The configured relationship edges are removed.
Proposed API
Add an additive fluent method:
public NPCPrefabBuilder WithRegion(S1API.Map.Region region)
It should apply the corresponding native EMapRegion value directly to the NPC component on the prefab during ConfigurePrefab, before network spawn, Awake, and NPCRelationData.Init.
Example:
builder
.WithIdentity("disco_davey", "Disco", "Davey")
.WithRegion(Region.Uptown)
.WithSpawnPosition(spawnPosition)
.WithRelationshipDefaults(relationship => relationship
.WithConnections<HerbertBleuball, TobiasWentworth>());
Acceptance criteria
- Add a documented, fluent
NPCPrefabBuilder.WithRegion(Region) method.
- Apply the region to the native prefab before relationship initialization.
- Preserve the configured region through Mono and IL2CPP network spawning.
- Ensure same-region relationship connections are not removed during
NPCRelationData.Init.
- Add focused contract coverage and validate the custom-NPC relationship flow in both runtimes.
Out of scope
- Making region declaration mandatory.
- Adding a public
Build() method or missing-region validation.
- Changing the existing fallback behavior for callers that do not use
WithRegion.
Summary
Custom NPCs currently cannot declare their designated map region through
NPCPrefabBuilderduringConfigurePrefab.Setting
NPC.Regionlater fromOnCreated()can be too late for native initialization. The base game'sNPCRelationData.Init(NPC)validates every relationship connection against the owning NPC's region and removes connections whose regions differ.Observed behavior
A custom Uptown supplier configured with connections to Herbert Bleuball and Tobias Wentworth sets:
WithRelationshipDefaults(...WithConnections<...>())duringConfigurePrefabRegion = Region.UptownduringOnCreated()During native relationship initialization, the custom NPC can still carry its inherited/default region. The game then logs:
The configured relationship edges are removed.
Proposed API
Add an additive fluent method:
It should apply the corresponding native
EMapRegionvalue directly to the NPC component on the prefab duringConfigurePrefab, before network spawn,Awake, andNPCRelationData.Init.Example:
Acceptance criteria
NPCPrefabBuilder.WithRegion(Region)method.NPCRelationData.Init.Out of scope
Build()method or missing-region validation.WithRegion.