Smart NPCs Service Reference

This reference guide covers the essential components and usage patterns of the Smart NPCs service, focusing on practical implementation details.

Core Components

SmartNPC Component

The primary component for adding voice capabilities to your game objects. This component handles:

  • Voice selection and management

  • Speech generation and playback

  • Audio queue management

  • Voice parameter customization

Implementation Patterns

Basic NPC Pattern

Simplest implementation for a speaking character:

using SkillfulAI.SmartNPCs;
using UnityEngine;

public class BasicNPC : MonoBehaviour
{
    private SmartNPC npc;

    void Start()
    {
        // Basic setup
        npc = gameObject.AddComponent<SmartNPC>();
        VoiceSelector.SetVoiceByCategory(npc, VoiceCategories.Male);
        npc.audioSource = gameObject.AddComponent<AudioSource>();
    }

    public void Speak(string text)
    {
        npc.Speak(text);
    }
}

Intelligent Speaking NPC Pattern

Combining Smart NPCs with Skillful Agents:

Multi-Voice Manager Pattern

For managing multiple NPCs with different voices:

Dialogue System Pattern

For handling complex dialogue sequences:

Interactive Tutorial Pattern

For creating voiced tutorials:

Best Practices

  1. Voice Selection

    • Choose appropriate voices for character types

    • Keep voice settings consistent for each character

    • Consider using voice categories for consistency

  2. Speech Management

    • Don't overlap speech from the same NPC

    • Implement proper queue management

    • Consider adding speech cooldowns

  3. Performance

    • Reuse SmartNPC components

    • Manage audio resources properly

    • Implement proper cleanup.

If you're stuck or need help, don't hesitate to reach out in our Discord Community

Last updated