Class NPCPrefabBuilder
Builder for composing NPC prefab configuration before network spawn. Use to declare networked components, spawn position, customer behavior, relationships, schedules, and appearance defaults.
public sealed class NPCPrefabBuilder
- Inheritance
-
NPCPrefabBuilder
- Inherited Members
- Extension Methods
Remarks
Configuration must be done in ConfigurePrefab(NPCPrefabBuilder) for proper save/load behavior. All builder methods return the builder instance for fluent chaining.
Methods
EnsureCustomer()
Ensures customer infrastructure for compatibility with existing prefab-builder declarations.
[Obsolete("Override NPC.IsCustomer to return true instead.", false)]
public NPCPrefabBuilder EnsureCustomer()
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Compatibility shim for existing mods. New NPC types should override IsCustomer.
EnsureDealer()
Ensures dealer infrastructure for compatibility with existing prefab-builder declarations.
[Obsolete("Override NPC.IsDealer to return true instead.", false)]
public NPCPrefabBuilder EnsureDealer()
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Compatibility shim for existing mods. New NPC types should override IsDealer. This marks the NPC type as dealer-capable; S1API will ensure the generated spawnable prefab has a Dealer-compatible NPC component before network registration when the selected base prefab does not already include one. When the NPC spawns, EnsureDealer() will be called automatically to initialize dealer functionality and ensure the messaging app displays the correct Dealer category badge.
EnsureDrinking(EquippablePath)
public NPCPrefabBuilder EnsureDrinking(EquippablePath drinkEquippablePath)
Parameters
drinkEquippablePathEquippablePath
Returns
EnsureDrinking(string?)
Adds drinking behaviour to the NPC. Enables equipping a drink and playing the drinking animation.
public NPCPrefabBuilder EnsureDrinking(string? drinkEquippablePath = null)
Parameters
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Adds DrinkItem as a standalone component. Use asset paths like "Avatar/Equippables/Beer" or "Avatar/Equippables/Coffee".
EnsureGraffiti(EquippablePath)
Adds graffiti behaviour. Use SprayPaint or Custom(string) for mod items.
public NPCPrefabBuilder EnsureGraffiti(EquippablePath sprayPaintEquippablePath)
Parameters
sprayPaintEquippablePathEquippablePath
Returns
EnsureGraffiti(string?)
Adds graffiti behaviour to the NPC. Enables spray painting with spray can equip and effects.
public NPCPrefabBuilder EnsureGraffiti(string? sprayPaintEquippablePath = null)
Parameters
sprayPaintEquippablePathstringResources path. Null for default. Use SprayPaint.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Adds GraffitiBehaviour and SprayPaint. If sprayPaintEquippablePath is null, tries: (1) Resources "Weapons/SprayPaint/SprayPaint_AvatarEquippable", (2) runtime fallback: first SprayPaint in scene with non-null _sprayPaintPrefab. Modders can pass a Resources path or bundle a spray paint equippable.
EnsureItemHolding(EquippablePath)
Adds item holding behaviour. Use Phone_Lowered, Flashlight, etc.
public NPCPrefabBuilder EnsureItemHolding(EquippablePath equippablePath)
Parameters
equippablePathEquippablePath
Returns
EnsureItemHolding(string?)
Adds generic item holding behaviour to the NPC. Enables equipping any AvatarEquippable item.
public NPCPrefabBuilder EnsureItemHolding(string? equippablePath = null)
Parameters
equippablePathstringResources path. Null for default. Use EquippablePath constants.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Adds HoldItem as a standalone component. Use Phone_Lowered, Flashlight, etc.
EnsureSmokeBreak(string?, bool?)
Adds smoke break behaviour to the NPC. Enables scheduled smoking with cigarette visual and animation.
public NPCPrefabBuilder EnsureSmokeBreak(string? cigarettePrefabPath = null, bool? debugMode = null)
Parameters
cigarettePrefabPathstringResources path to cigarette EquippableData or TPEquippedItem. Null to try default paths.
debugModebool?Whether to enable SmokeBreakBehaviour debug logging. Null leaves the current value unchanged.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Adds SmokeBreakBehaviour and SmokeCigarette. Requires cigarette equippable data. If cigarettePrefabPath is null, tries the current base game Resources path "equippables/cigarette/Cigarette", then runtime SmokeCigarette data fallbacks, then the legacy CigarettePrefab fallback for older game builds. Modders can pass a Resources path to an EquippableData asset or a TPEquippedItem prefab. Adds a placeholder smoke location.
EnsureSupplier()
Ensures supplier infrastructure for compatibility with existing prefab-builder declarations.
[Obsolete("Override NPC.IsSupplier to return true instead.", false)]
public NPCPrefabBuilder EnsureSupplier()
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Compatibility shim for existing mods. New NPC types should override IsSupplier. Supplier NPCs support dead-drop orders, supplier meetings, delivery unlocks, and debt tracking. S1API reserves a location-dialogue schedule action required by the native supplier lifecycle. A custom NPC cannot be both a dealer and a supplier.
WithAppearanceDefaults(Action<AvatarDefaultsBuilder>)
Declares appearance defaults via a wrapper builder. Values are embedded as an AvatarSettings asset reference on the prefab and applied to the runtime avatar on spawn (server and clients).
public NPCPrefabBuilder WithAppearanceDefaults(Action<NPCPrefabBuilder.AvatarDefaultsBuilder> configure)
Parameters
configureAction<NPCPrefabBuilder.AvatarDefaultsBuilder>
Returns
WithCustomerDefaults(Action<CustomerDataBuilder>)
Configures customer behavior defaults using the CustomerDataBuilder.
public NPCPrefabBuilder WithCustomerDefaults(Action<CustomerDataBuilder> configure)
Parameters
configureAction<CustomerDataBuilder>Action to configure customer defaults using the builder.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Configure spending behavior, order frequency, customer standards, product preferences, and relationship requirements. Override IsCustomer to declare customer capability. This method retains the legacy implicit declaration behavior for source and behavioral compatibility. This configuration is essential for proper save/load behavior and must be done in ConfigurePrefab(NPCPrefabBuilder).
WithDealerDefaults(Action<DealerDataBuilder>)
Configures dealer behavior defaults using the DealerDataBuilder.
public NPCPrefabBuilder WithDealerDefaults(Action<DealerDataBuilder> configure)
Parameters
configureAction<DealerDataBuilder>Action to configure dealer defaults using the builder.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Configure dealer settings such as signing fee, commission cut, dealer type, quality restrictions, and deal tracking. Override IsDealer to declare dealer capability. This method retains the legacy implicit declaration behavior for source and behavioral compatibility. This configuration is essential for proper save/load behavior and must be done in ConfigurePrefab(NPCPrefabBuilder).
WithIcon(Sprite)
Declares the icon sprite to be embedded on the prefab. This sprite is used for UI elements such as messages, contacts, and relationships. Should be 64x64 or 128x128 pixels. Uses default if not set.
public NPCPrefabBuilder WithIcon(Sprite icon)
Parameters
iconSpriteOptional sprite for UI elements. Uses default if null.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
WithIdentity(string, string, string)
Declares identity defaults (ID, first and last name) to be embedded on the prefab. These values are applied on spawn on both server and clients.
public NPCPrefabBuilder WithIdentity(string id, string firstName, string lastName)
Parameters
Returns
WithInventoryDefaults(Action<RandomInventoryItemsBuilder>)
Declares default inventory configuration for this NPC type. Supports startup items (always present) and random cash (varies on each sleep).
public NPCPrefabBuilder WithInventoryDefaults(Action<RandomInventoryItemsBuilder> configure)
Parameters
configureAction<RandomInventoryItemsBuilder>Action to configure inventory defaults using the builder.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
All configurations are optional. Applied when the NPC is spawned.
WithRegion(Region)
Sets the NPC's designated map region on the native prefab before it is network-spawned.
public NPCPrefabBuilder WithRegion(Region region)
Parameters
regionRegionThe NPC's designated map region.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Configure this in ConfigurePrefab(NPCPrefabBuilder) when the NPC has relationship connections. The native relationship initializer removes connections to NPCs in a different region, so setting Region later in OnCreated() is too late.
WithRelationshipDefaults(Action<NPCRelationshipDataBuilder>)
Configures default relationship settings (delta, unlock type, connections) for this NPC type. Applied to the instance after spawn and before save-data hydration.
public NPCPrefabBuilder WithRelationshipDefaults(Action<NPCRelationshipDataBuilder> configure)
Parameters
configureAction<NPCRelationshipDataBuilder>Action to configure relationship defaults using the builder.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Configure starting relationship level, unlock state, and connections to other NPCs. This configuration must be done in ConfigurePrefab(NPCPrefabBuilder) for proper save/load behavior.
WithSchedule(params IScheduleActionSpec[])
Declares a schedule using a params array of specs for convenience.
public NPCPrefabBuilder WithSchedule(params IScheduleActionSpec[] specs)
Parameters
specsIScheduleActionSpec[]Array of schedule action specifications.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
WithSchedule(Action<PrefabScheduleBuilder>)
Defines the NPC's schedule using the PrefabScheduleBuilder. Schedule actions are planned and pre-created on the prefab.
public NPCPrefabBuilder WithSchedule(Action<PrefabScheduleBuilder> configure)
Parameters
configureAction<PrefabScheduleBuilder>Action to configure schedule using the builder.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Use to configure movement patterns, building visits, and timed activities. The plan is applied at runtime to activate precreated actions. Schedule configuration must be done in ConfigurePrefab(NPCPrefabBuilder) for proper save/load behavior.
WithSchedule(IEnumerable<IScheduleActionSpec>)
Declares a schedule using a prebuilt set of specs. Use when composing plans externally or sharing between NPC types.
public NPCPrefabBuilder WithSchedule(IEnumerable<IScheduleActionSpec> specs)
Parameters
specsIEnumerable<IScheduleActionSpec>Enumerable collection of schedule action specifications.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
WithSpawnPosition(Vector3)
Sets the spawn position with default rotation. Applied every time the NPC is spawned.
public NPCPrefabBuilder WithSpawnPosition(Vector3 position)
Parameters
positionVector3World position where the NPC will spawn.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
WithSpawnPosition(Vector3, Quaternion)
Sets the spawn position and rotation for this NPC type. Applied every time the NPC is spawned (new games and loaded games).
public NPCPrefabBuilder WithSpawnPosition(Vector3 position, Quaternion rotation)
Parameters
positionVector3World position where the NPC will spawn.
rotationQuaternionRotation for the NPC (defaults to Quaternion.identity).
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Use world coordinates. Consider building entrances, roads, and safe spawn areas. Position should be on a walkable surface.
WithSupplierDefaults(Action<SupplierDataBuilder>)
Configures native supplier data for this NPC type.
public NPCPrefabBuilder WithSupplierDefaults(Action<SupplierDataBuilder> configure)
Parameters
configureAction<SupplierDataBuilder>Action that defines order limits, delivery items, and supplier messages.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Remarks
Override IsSupplier to declare supplier capability. This method retains the legacy implicit declaration behavior for source and behavioral compatibility.
Exceptions
- ArgumentNullException
Thrown when
configureis null.
WithVoice(NPCVoiceDefinition)
Selects a supported base-game voice while preserving the prefab's inherited pitch.
public NPCPrefabBuilder WithVoice(NPCVoiceDefinition voice)
Parameters
voiceNPCVoiceDefinitionThe S1API-owned voice definition.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Exceptions
- ArgumentNullException
Thrown when
voiceisnull.- InvalidOperationException
Thrown when the voice database or custom NPC data is unavailable.
WithVoice(NPCVoiceDefinition, float)
Selects a supported base-game voice and default pitch.
public NPCPrefabBuilder WithVoice(NPCVoiceDefinition voice, float pitch)
Parameters
voiceNPCVoiceDefinitionThe S1API-owned voice definition.
pitchfloatThe default playback pitch, from 0.1 through 4.0.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Exceptions
- ArgumentNullException
Thrown when
voiceisnull.- ArgumentOutOfRangeException
Thrown when
pitchis outside the supported range.- InvalidOperationException
Thrown when the voice database or custom NPC data is unavailable.
WithVoice(string)
Selects a supported base-game voice by its stable, case-insensitive identifier.
public NPCPrefabBuilder WithVoice(string identifier)
Parameters
identifierstringAn identifier from NPCVoiceCatalog.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Exceptions
- ArgumentException
Thrown when
identifieris missing or unsupported.- InvalidOperationException
Thrown when the voice database or custom NPC data is unavailable.
WithVoice(string, float)
Selects a supported base-game voice and default pitch by identifier.
public NPCPrefabBuilder WithVoice(string identifier, float pitch)
Parameters
identifierstringAn identifier from NPCVoiceCatalog.
pitchfloatThe default playback pitch, from 0.1 through 4.0.
Returns
- NPCPrefabBuilder
The builder instance for fluent chaining.
Exceptions
- ArgumentException
Thrown when
identifieris missing or unsupported.- ArgumentOutOfRangeException
Thrown when
pitchis outside the supported range.- InvalidOperationException
Thrown when the voice database or custom NPC data is unavailable.