Class NPC
Abstract base class for creating custom NPCs with modular architecture supporting both physical and non-physical NPCs. Physical NPCs are visible in the game world with 3D models, movement, and direct interaction. Non-physical NPCs are invisible contacts primarily used for messaging and phone interactions.
public abstract class NPC : Saveable, IEntity, IHealth
- Inheritance
-
NPC
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
NPCs provide access to component systems: Appearance, Dialogue, Schedule, Customer, Relationship, Inventory, and Movement. Customer, relationship, and schedule configuration must be done in ConfigurePrefab(NPCPrefabBuilder) for proper save/load behavior.
Constructors
NPC()
Base constructor for a new NPC. Identity is configured via ConfigurePrefab(NPCPrefabBuilder) using WithIdentity(string, string, string) and optionally WithIcon(Sprite).
protected NPC()
Remarks
Not intended for direct instancing. Create your derived class and let S1API handle instancing. Identity information (ID, firstName, lastName, icon) must be provided in ConfigurePrefab(NPCPrefabBuilder) using the builder methods.
NPC(string, string?, string?, Sprite?)
Backwards-compatible constructor for non-physical NPCs that provides identity directly via parameters. This constructor is intended for backwards compatibility with mods that used the old constructor pattern.
[Obsolete("Use the parameterless constructor and configure identity via ConfigurePrefab with NPCPrefabBuilder.WithIdentity. This constructor is provided for backwards compatibility with non-physical NPCs.")]
protected NPC(string id, string? firstName, string? lastName, Sprite? icon = null)
Parameters
idstringUnique identifier for the NPC.
firstNamestringThe first name for the NPC.
lastNamestringThe last name for the NPC. Can be null.
iconSpriteThe icon sprite for the NPC. Can be null to use default.
Remarks
This constructor is marked as obsolete. For new code, use the parameterless constructor and configure identity via ConfigurePrefab(NPCPrefabBuilder) using WithIdentity(string, string, string) and optionally WithIcon(Sprite).
This constructor is appropriate for non-physical NPCs (where IsPhysical returns false) that
don't require prefab configuration. Physical NPCs should use ConfigurePrefab(NPCPrefabBuilder) for proper network spawn support.
Fields
All
List of all NPCs within the base game and modded.
public static readonly List<NPC> All
Field Value
Responses
A list of text responses you've added to your NPC.
protected readonly List<Response> Responses
Field Value
Properties
Aggressiveness
How aggressive this NPC is towards others.
public float Aggressiveness { get; set; }
Property Value
Appearance
Access to the appearance customization system for visual avatar management.
public NPCAppearance Appearance { get; }
Property Value
CombatBehaviour
The current CombatBehaviour instance.
public CombatBehaviour CombatBehaviour { get; }
Property Value
ConversationCanBeHidden
Set's whether the text message can be deleted/hidden
public bool ConversationCanBeHidden { get; set; }
Property Value
CurrentHealth
The current health the NPC has.
public float CurrentHealth { get; }
Property Value
CurrentVehicle
The current vehicle the NPC is occupying, if any.
public LandVehicle? CurrentVehicle { get; }
Property Value
CustomNpcsReady
Whether all custom NPCs have been instantiated and finalized. This flag is set to true once all custom NPC types have been spawned and initialized. Mods can check this to ensure custom NPCs are ready before performing operations that depend on them.
public static bool CustomNpcsReady { get; }
Property Value
Customer
Access to the customer behavior system for NPCs that act as business customers.
public NPCCustomer Customer { get; }
Property Value
Dealer
Access to the dealer system for NPCs that act as product distributors.
public NPCDealer Dealer { get; }
Property Value
Dialogue
Access to the dialogue system for interactive conversations and dialogue trees.
public NPCDialogue Dialogue { get; }
Property Value
Drinking
Access to the drinking action for this NPC.
public NPCDrinking Drinking { get; }
Property Value
FirstName
The first name of this NPC.
public string FirstName { get; set; }
Property Value
FullName
The full name of this NPC. If there is no last name, it will just return the first name.
public string FullName { get; }
Property Value
ID
The unique identifier to assign to this NPC. Used when saving and loading. Probably other things within the base game code.
public string ID { get; protected set; }
Property Value
Icon
The icon assigned to this NPC.
public Sprite Icon { get; set; }
Property Value
- Sprite
Inventory
Access to the inventory system for item management.
public NPCInventory Inventory { get; }
Property Value
IsConscious
Whether the NPC is currently conscious or not.
public bool IsConscious { get; }
Property Value
IsDead
Whether the NPC is dead or not.
public bool IsDead { get; }
Property Value
IsDealer
Determines if the NPC has dealer functionality. Override as true for NPCs that should be dealers.
public virtual bool IsDealer { get; }
Property Value
Remarks
Dealer NPCs (true): Can manage customers, handle contracts, accept cash payments, and track inventory for sales.
When true, the NPC prefab will use the "Dealer" network prefab instead of "CivilianNPC".
Non-dealer NPCs (false): Regular NPCs without dealer-specific functionality.
IsInBuilding
Whether the NPC is currently inside a building or not.
public bool IsInBuilding { get; }
Property Value
IsInVehicle
Whether the NPC is currently inside a vehicle or not.
public bool IsInVehicle { get; }
Property Value
IsInvincible
Whether the NPC is invincible or not.
public bool IsInvincible { get; set; }
Property Value
IsKnockedOut
Whether the NPC is knocked out or not.
public bool IsKnockedOut { get; }
Property Value
IsPanicking
Whether the NPC is currently panicking or not.
public bool IsPanicking { get; }
Property Value
IsPhysical
Determines if the NPC is visible in the game world. Override as true for physical NPCs with 3D models, movement, and direct interaction.
public virtual bool IsPhysical { get; }
Property Value
Remarks
Physical NPCs (true): Visible in world, have collision detection, can move and follow schedules, can be damaged/healed.
Non-physical NPCs (false): Invisible, primarily for messaging and phone contacts, cannot move or be directly interacted with.
IsUnsettled
Whether the NPC is currently unsettled or not.
public bool IsUnsettled { get; }
Property Value
IsVisible
UNCONFIRMED: Whether the NPC is currently visible to the player or not. If you confirm this, please let us know so we can update the documentation!
public bool IsVisible { get; }
Property Value
ItemHolding
Access to the item holding action for this NPC.
public NPCItemHolding ItemHolding { get; }
Property Value
LastName
The last name of this NPC.
public string LastName { get; set; }
Property Value
MaxHealth
The maximum health the NPC has.
public float MaxHealth { get; set; }
Property Value
Movement
Access to the movement system for controlling NPC movement and navigation.
public NPCMovement Movement { get; }
Property Value
NPCId
Static NPC ID for this NPC type. Used to resolve connections during prefab configuration when NPC instances are not yet available. Override this in derived classes to provide the NPC ID string (e.g., "kyle_cooley", "ludwig_meyer").
public static string? NPCId { get; }
Property Value
Remarks
For built-in NPC wrappers, this should return the ID string that matches the base game NPC. For custom NPCs, this should return the ID configured via WithIdentity(string, string, string).
Position
The world position of the NPC.
public Vector3 Position { get; set; }
Property Value
- Vector3
Region
The region the NPC is associated with. Note: Not the region they're in currently. Just the region they're designated to.
public Region Region { get; set; }
Property Value
Relationship
Access to the relationship system for social connections and relationships with the player.
public NPCRelationship Relationship { get; }
Property Value
RequiresRegionUnlocked
UNCONFIRMED: Whether the NPC requires the region unlocked in order to deal to. If you confirm this, please let us know so we can update the documentation!
public bool RequiresRegionUnlocked { get; set; }
Property Value
Scale
Sets the scale of the NPC.
public float Scale { get; set; }
Property Value
Schedule
Access to the schedule system for movement and activity scheduling.
public NPCSchedule Schedule { get; }
Property Value
Smoking
Access to the smoking action for this NPC.
public NPCSmoking Smoking { get; }
Property Value
SprayPainting
Access to the spray painting action for this NPC.
public NPCSprayPainting SprayPainting { get; }
Property Value
Transform
The transform of the NPC. Please do not set the properties of this transform.
public Transform Transform { get; }
Property Value
- Transform
gameObject
INTERNAL: Tracking for the GameObject associated with this NPC. Not intended for use by modders!
public GameObject gameObject { get; }
Property Value
- GameObject
Methods
ClearConversationCategories()
Clears the NPC's conversation categories, removing any badge (C/S/D) from the messages UI. This makes the NPC appear like Uncle Nelson - present in messages but without a category badge.
public void ClearConversationCategories()
ConfigurePrefab(NPCPrefabBuilder)
Override to configure NPC components and default behavior before the NPC is spawned. Called during prefab creation to set up spawn position, customer behavior, relationships, and schedules.
protected virtual void ConfigurePrefab(NPCPrefabBuilder builder)
Parameters
builderNPCPrefabBuilderPrefab builder for configuring this NPC type.
Remarks
Customer, relationship, and schedule configuration must be done here for proper save/load behavior and network compatibility. Use the builder pattern for fluent configuration. Runtime initialization should be done in OnCreated() instead.
Damage(int)
Deals damage to the NPC.
public void Damage(int amount)
Parameters
amountintThe amount of damage to deal.
Get(string)
Gets the instance of an NPC by its unique ID. Supports already-materialized wrappers and built-in NPC wrappers.
public static NPC? Get(string npcId)
Parameters
npcIdstringThe S1 NPC ID.
Returns
- NPC
The matching wrapper instance, or null if one could not be resolved.
Get<T>()
Gets the instance of an NPC. Supports base NPCs as well as other mod NPCs. For base NPCs, S1API.Entities.NPCs.
public static NPC? Get<T>() where T : NPC
Returns
Type Parameters
TThe NPC class to get the instance of.
Goto(Vector3)
Tells the NPC to travel to a specific position in world space.
public void Goto(Vector3 position)
Parameters
positionVector3The position to travel to.
Heal(int)
Heals the NPC.
public void Heal(int amount)
Parameters
amountintThe amount of health to heal.
Kill()
Kills the NPC.
public void Kill()
KnockOut()
Knocks the NPC out. NOTE: Does not work for invincible NPCs.
public void KnockOut()
LerpScale(float, float)
Smoothly scales the NPC over lerpTime.
public void LerpScale(float scale, float lerpTime)
Parameters
OnCreated()
Called when the NPC is fully created and spawned. Override for runtime initialization after all components are set up. Use this to configure appearance, dialogue systems, subscribe to events, enable schedule system, and set basic properties.
protected override void OnCreated()
Remarks
Called after the NPC is instantiated and all components are initialized. Appearance, dialogue, and schedule setup should be done here rather than in the constructor.
OnResponseLoaded(Response)
Called when a text message response is loaded from the save file. Override to re-attach callbacks to loaded responses.
protected virtual void OnResponseLoaded(Response response)
Parameters
responseResponseThe response that was loaded from save data.
Panic()
Causes the NPC to become panicked. Currently host/server-only: non-host clients hit the SafeIsServer guard below and this becomes a silent no-op, which is inconsistent with other server-RPC-style wrappers in the API and with the runtime docs.
public void Panic()
PreRegisterAllNpcPrefabs()
Scans loaded assemblies for subclasses of S1API.Entities.NPC and pre-registers their prefabs.
public static void PreRegisterAllNpcPrefabs()
PreRegisterPrefabForType(Type)
Pre-registers a per-type NPC prefab into FishNet spawnables without creating a live instance. Should be called on both server and client before any NPC instances are spawned.
public static void PreRegisterPrefabForType(Type npcType)
Parameters
npcTypeType
RefreshMessagingIcons()
public void RefreshMessagingIcons()
Revive()
Revives the NPC. Note: custom NPC revive currently routes through a temporary NPCHealth patch with a reflective fallback meant for pre-network-init safety; live multiplayer calls should eventually stay on the authoritative network path.
public void Revive()
SendTextMessage(string, Response[]?, float, bool)
Sends a text message from this NPC to the players. Supports responses with callbacks for additional logic.
public void SendTextMessage(string message, Response[]? responses = null, float responseDelay = 1, bool network = true)
Parameters
messagestringThe message you want the player to see. Unity rich text is allowed.
responsesResponse[]Instances of Response to display.
responseDelayfloatThe delay between when the message is sent and when the player can reply.
networkboolWhether this should propagate to all players or not.
SetEquippable(EquippablePath)
Sets an equippable item for the NPC using a type-safe path.
public void SetEquippable(EquippablePath equippablePath)
Parameters
equippablePathEquippablePathUse EquippablePath (e.g. Phone_Lowered).
SetEquippable(string)
Sets an equippable item for the NPC.
public void SetEquippable(string assetPath)
Parameters
assetPathstringThe asset path to the equippable item. Use EquippablePath or Misc.
StopPanicking()
Causes the NPC to stop panicking, if they are currently.
public void StopPanicking()
Unsettle(float)
Causes the NPC to become unsettled. UNCONFIRMED: Will panic them for a short duration.
public void Unsettle(float duration)
Parameters
durationfloatLength of time they should stay unsettled.
Events
OnDeath
Called when the NPC died.
public event Action OnDeath
Event Type
OnInventoryChanged
Called when the NPC's inventory contents change.
public event Action OnInventoryChanged