Skip to content

Add NPCPrefabBuilder.WithRegion for pre-spawn region configuration #154

Description

@ifBars

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions