Barks
Short ambient lines characters say without player interaction. Guards muttering threats, merchants hawking wares, villagers chatting -- barks bring the world to life without opening a full dialogue UI.
Overview
The bark system has four components:
| Component | Purpose |
|---|---|
BarkData | A single bark line (text, duration, audio, priority) |
BarkCollection | ScriptableObject containing an array of barks with selection logic |
Barker | MonoBehaviour that triggers barks on NPCs |
BarkUI | World-space UI that displays bark text above characters |
BarkUIPool | Object pool for efficient multi-character barking |
BarkData
A serializable data class representing one bark line.
| Field | Type | Default | Description |
|---|---|---|---|
text | string | -- | The bark text to display |
characterId | string | -- | Speaker character ID (for name/portrait lookup) |
duration | float | 3f | How long to display (seconds) |
priority | int | 0 | Queue priority (higher = shown first) |
audioClip | AudioClip | -- | Unity audio clip to play |
fmodEventPath | string | -- | FMOD event path (used when global audio is FMOD) |
Constructors
var bark = new BarkData();
var bark = new BarkData("Watch yourself!", 4f);
var bark = new BarkData("Welcome to my shop!", "merchant_01", 3f);
BarkCollection
A ScriptableObject that groups barks for an NPC. Create via Assets > Create > CraftWorks > DialogueCraft > Bark Collection.
| Field | Description |
|---|---|
barks | Array of BarkData entries |
selectionMode | How to pick the next bark |
Selection Modes
| Mode | Enum | Behavior |
|---|---|---|
| Random | BarkSelectionMode.Random | Pick a random bark each time |
| Sequential | BarkSelectionMode.Sequential | Cycle through in order, wrapping |
| First | BarkSelectionMode.First | Always use the first bark |
BarkData next = collection.GetNext(); // Returns bark based on selectionMode
collection.Reset(); // Reset sequential index to 0
Barker Component
The main MonoBehaviour for making NPCs bark. Add it to any character GameObject.
[AddComponentMenu("CraftWorks/DialogueCraft/Bark/Barker")]
Inspector Settings
Bark Settings
| Field | Description |
|---|---|
characterId | Character ID for this barker (applied to barks missing a characterId) |
barkCollection | BarkCollection ScriptableObject to pull barks from |
customBarks | Inline list of BarkData (used when no collection is assigned) |
Triggers
| Field | Default | Description |
|---|---|---|
barkOnTriggerEnter | false | Bark when a tagged object enters the trigger collider |
requiredTag | "Player" | Only trigger for objects with this tag |
randomBarks | false | Periodically bark at random intervals |
minInterval | 10f | Minimum seconds between random barks (5-120) |
maxInterval | 30f | Maximum seconds between random barks (5-300) |
Cooldown
| Field | Default | Description |
|---|---|---|
cooldown | 5f | Minimum seconds between any two barks (0-30) |
UI
| Field | Description |
|---|---|
dedicatedBarkUI | Optional per-character BarkUI. If not set, uses the global BarkUIPool. |
uiOffset | World-space offset from the barker's position (default: (0, 2, 0)) |
Events
| Event | Signature | Description |
|---|---|---|
OnBark | UnityEvent<BarkData> | Fired when a bark is triggered |
Trigger Modes
Proximity trigger: Enable barkOnTriggerEnter and add a Collider (set to trigger) on the same GameObject. Works with both 3D (OnTriggerEnter/OnTriggerExit) and 2D (OnTriggerEnter2D/OnTriggerExit2D) colliders.
Random interval: Enable randomBarks. The barker schedules the next bark at a random time between minInterval and maxInterval. Cooldown still applies.
Manual trigger: Call Bark() from code or UnityEvents.
Bark Resolution
When Bark() is called, the barker resolves a BarkData:
- If
barkCollectionis assigned, callsbarkCollection.GetNext() - Otherwise, picks randomly from
customBarks - If the bark has no
characterId, the barker'scharacterIdis applied
API
var barker = GetComponent<Barker>();
// Trigger a bark from the configured collection/custom list
barker.Bark();
// Bark a specific text
barker.Bark("Halt! Who goes there?", duration: 4f);
// Bark specific data
barker.Bark(new BarkData("Fine day for a sale!", "merchant", 3f));
// Stop the current bark
barker.StopBark();
// Check cooldown
if (barker.CanBark)
{
barker.Bark();
}
UI Resolution
The barker resolves a BarkUI in this order:
dedicatedBarkUI-- A specificBarkUIassigned in the Inspector- Global
BarkUIPool-- Found viaFindObjectOfType<BarkUIPool>() - Any
BarkUIin the scene -- Fallback viaFindObjectOfType<BarkUI>()
BarkUI Component
World-space UI that displays bark text above characters. Typically placed on a World Space Canvas.
Inspector Settings
UI References
| Field | Description |
|---|---|
textComponent | TextMeshProUGUI for bark text (required) |
backgroundPanel | Optional background GameObject (hidden when no bark active) |
nameLabel | Optional TextMeshProUGUI for the character name |
Positioning
| Field | Default | Description |
|---|---|---|
offset | (0, 2, 0) | Offset from follow target (overridden by Barker's uiOffset) |
faceCamera | true | Billboard toward camera each frame |
targetCamera | Main Camera | Camera to face (auto-finds Camera.main) |
Animation
| Field | Default | Description |
|---|---|---|
fadeDuration | 0.3f | Fade in/out duration (seconds) |
useTypewriter | false | Reveal text character by character |
typewriterSpeed | 30f | Characters per second (when typewriter enabled) |
Audio
| Field | Description |
|---|---|
audioSource | AudioSource for playing bark audio clips |
Lifecycle
When Show(bark, target) is called:
- Starts following
targettransform at the configured offset - Sets up text, character name, and background
- Plays audio (FMOD event or Unity AudioClip depending on global setting)
- Fades in over
fadeDuration - If
useTypewriteris enabled, reveals text character by character (supports inline speed/pause tags) - Waits for
bark.durationseconds - Fades out over
fadeDuration - Hides and marks itself as available
API
var barkUI = GetComponent<BarkUI>();
barkUI.Show(barkData, npcTransform); // Show bark above NPC
barkUI.Hide(); // Immediately hide
bool active = barkUI.IsShowing; // Check if displaying
Character Name Display
If nameLabel is assigned and the bark has a characterId, the UI looks up the character in DialogueCraftSettings.Characters and displays displayName. If no character is found, the raw characterId is shown. If no characterId is set, the name label is hidden.
BarkUIPool
Manages a pool of BarkUI instances for scenes with multiple barking NPCs. Without a pool, multiple barkers would fight over a single BarkUI.
Setup
- Create a
BarkUIprefab (World Space Canvas withBarkUI,TextMeshProUGUI, optional background). - Add a
BarkUIPoolcomponent to a scene GameObject. - Assign the prefab and configure pool size.
Inspector Settings
| Field | Default | Description |
|---|---|---|
barkUIPrefab | -- | Prefab to instantiate (required) |
initialPoolSize | 5 | Pre-created instances on Awake (1-20) |
maxPoolSize | 10 | Hard limit on pool growth (1-50) |
queueBarks | true | Queue barks when no UI available |
maxQueueSize | 5 | Maximum queued barks (0-20) |
How It Works
- On
Awake(), the pool instantiatesinitialPoolSizeBarkUI children. - When a
Barkerrequests a UI viaGetBarkUI(), the pool returns the first instance whereIsShowing == false. - If all instances are busy and the pool is below
maxPoolSize, a new instance is created. - If at max capacity and
queueBarksis enabled, barks are queued and dispatched each frame as UIs become available.
API
var pool = FindObjectOfType<BarkUIPool>();
// Get an available UI (returns null if pool full and queue disabled)
BarkUI ui = pool.GetBarkUI();
// Show a bark (auto-queues if no UI available)
pool.ShowBark(barkData, targetTransform);
// Manually queue
pool.QueueBark(barkData, targetTransform);
// Hide all active barks and clear the queue
pool.HideAll();
Runtime API Summary
Triggering Barks from Code
// Through a Barker component
barker.Bark();
barker.Bark("Custom text", 4f);
barker.Bark(customBarkData);
// Through a BarkUIPool (no Barker needed)
pool.ShowBark(new BarkData("Alert!", "guard", 3f), guardTransform);
// Direct BarkUI control
barkUI.Show(barkData, npcTransform);
barkUI.Hide();
Audio
Bark audio follows the global audio backend setting:
- Unity: Plays
bark.audioClipthroughBarkUI.audioSource - FMOD: Plays
bark.fmodEventPathviaAudioProviderManager.Provider.PlayOneShot()
Configure the global backend in DialogueCraft Settings > Audio Source (AudioSourceType.Unity or AudioSourceType.FMOD).
Events
Use the Barker.OnBark UnityEvent to react to barks in other systems:
barker.OnBark.AddListener((BarkData bark) =>
{
// Update quest journal, trigger animation, etc.
Debug.Log($"{bark.characterId} says: {bark.text}");
});