> For the complete documentation index, see [llms.txt](https://malbersanimations.gitbook.io/animal-controller/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://malbersanimations.gitbook.io/animal-controller/malbers-questforge/quest-system/objectives/talk-to-objective.md).

# Talk To Objective

### Overview

`TalkToObjective` tracks whether the player has spoken to a specific NPC. It listens to `QuestEventType.NPCTalkedTo` events published via the `QuestEventBus` and sets a completion flag when an event with a matching NPC ID arrives.

It supports two targeting modes:

* **General** — completes when the player talks to the NPC at all, regardless of which dialogue is triggered
* **Specific dialogue** — completes only when a particular dialogue ID is started with the NPC, allowing objectives to require a specific conversation rather than any interaction

`TalkToObjective` is a binary objective — it is either done or not done, with no count. It is added as an objective entry on a **Quest ScriptableObject**. It is not a component. The event that satisfies it is fired by the dialogue system via `QuestEventReporter.Instance.ReportNPCTalkedTo(npcId, dialogueId)`.

***

### Fields

**Talk To Objective Settings**

| Field                    | Type     | Description                                                                                                                                                      |
| ------------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **NPC ID**               | `string` | The NPC identifier this objective listens for. Must match the `npcId` passed to `QuestEventReporter.ReportNPCTalkedTo()` when dialogue with this NPC begins.     |
| **Specific Dialogue ID** | `string` | Optional. When set, the objective only completes if the reported `dialogueId` also matches this value. Leave empty to complete on any conversation with the NPC. |

***

#### Inherited Fields (from `QuestObjective`)

| Field            | Type     | Description                                                                          |
| ---------------- | -------- | ------------------------------------------------------------------------------------ |
| **Objective ID** | `string` | Auto-generated GUID uniquely identifying this objective within its quest.            |
| **Description**  | `string` | Text shown to the player in the Quest Journal and HUD tracker.                       |
| **Is Optional**  | `bool`   | When `true`, this objective does not need to be completed for the quest to complete. |

***

### How It Works

**Matching**

When an `NPCTalkedToEventData` event arrives, `QuestManager` sets progress flags:

```
progress.SetFlag("talked_to_{npcId}", true)

// If a dialogueId was reported:
progress.SetFlag("talked_to_{npcId}_{dialogueId}", true)
```

Both flags are always written when a dialogue ID is present — the specific flag and the general flag are set simultaneously.

**Completion Check**

```
specificDialogueId set:   progress.GetFlag("talked_to_{npcId}_{specificDialogueId}")
otherwise:                progress.GetFlag("talked_to_{npcId}")
```

Since `QuestManager` sets both flags when a dialogue ID is provided, an objective with `specificDialogueId` set will only complete when that exact dialogue fires — but an objective without `specificDialogueId` will complete regardless of which dialogue is triggered with that NPC.

**Event Subscription Lifecycle**

When the parent quest starts, `QuestManager` calls `SubscribeToEvents(eventBus)`, subscribing this objective to `QuestEventType.NPCTalkedTo`. When the quest ends, `UnsubscribeFromEvents(eventBus)` removes the subscription.

***

### Firing the Event

`TalkToObjective` does not poll for NPC proximity. Something in the scene must call:

```csharp
QuestEventReporter.Instance.ReportNPCTalkedTo("ElderMaren");

// Or with a specific dialogue ID:
QuestEventReporter.Instance.ReportNPCTalkedTo("ElderMaren", "quest_intro_dialogue");
```

Common integration points:

* A **Dialogue Graph Start node** or **Dialogue Graph completion callback** — wired to call `ReportNPCTalkedTo` when a conversation begins or ends
* A **Malbers Event** fired from within a dialogue node, connected to `QuestEventReporter.ReportNPCTalkedTo`
* A `QuestTrigger` component on the NPC with `Activation Method: OnInteract`, performing a `StartQuest` or `CompleteObjective` action

***

### Connecting to the Scene

The `npcId` set on the objective must exactly match the string passed to `ReportNPCTalkedTo` from the dialogue system. There is no dedicated `QuestTalkable` component — the NPC's dialogue setup is responsible for firing the event at the appropriate point in the conversation.

| Quest ScriptableObject               | Dialogue / Scene Setup                                          |
| ------------------------------------ | --------------------------------------------------------------- |
| `npcId = "ElderMaren"`               | Dialogue fires `ReportNPCTalkedTo("ElderMaren")`                |
| `specificDialogueId = "quest_intro"` | Dialogue fires `ReportNPCTalkedTo("ElderMaren", "quest_intro")` |

***

### Example Configurations

**"Speak to Elder Maren"** — any conversation

```
NPC ID:               "ElderMaren"
Specific Dialogue ID: (empty)
Description:          Speak to Elder Maren
```

**"Hear the Elder's warning"** — specific dialogue required

```
NPC ID:               "ElderMaren"
Specific Dialogue ID: "elder_warning_dialogue"
Description:          Listen to Elder Maren's Warning
```

*Only completes when the dialogue system reports `"elder_warning_dialogue"` specifically — other conversations with Elder Maren do not count.*

**"Report back to the Captain"** — turn-in conversation

```
NPC ID:               "CaptainVarris"
Specific Dialogue ID: (empty)
Description:          Report back to Captain Varris
```

***

#### Other Notes

* `npcId` and `specificDialogueId` matching is exact and case-sensitive.
* The `talked_to_{npcId}` general flag is always set when any conversation with the NPC is reported, even when a `specificDialogueId` is also provided. This means a general `TalkToObjective` (no specific dialogue) will complete even if a more targeted conversation fires the event.
* `TalkToObjective` is a one-way flag — once set to `true`, it cannot be unset during an active quest session. If the quest is reset via `ResetProgress()`, the flag is cleared and the objective can be completed again.
* If two active quests both have a `TalkToObjective` with the same `npcId`, a single conversation satisfies both simultaneously.
* The `specificDialogueId` field enables multi-step NPC interactions within the same quest — for example, requiring the player to first trigger a "quest given" dialogue, then later a separate "quest complete" dialogue, each tracked by a different `TalkToObjective`.
