# 07 Recipes

Common patterns ready to copy. Each recipe is fully Blueprint-doable.

## 1. Patrol Route

**Goal:** AI walks a fixed list of waypoints in order, looping.

{% stepper %}
{% step %}

### Place nodes along your patrol path

Connect them with bidirectional paths.
{% endstep %}

{% step %}

### In your AI Blueprint, store the patrol nodes as an array

{% endstep %}

{% step %}

### On a state change ("start patrolling"), loop through the array

* For each node, call **OWP AI Move To** with **Target Actor** = the node.
* Wait for **On Success** before moving to the next.
  {% endstep %}

{% step %}

### When you reach the end, restart from index 0.

{% endstep %}
{% endstepper %}

**Tip:** Use **Get Patrol Route** to auto-generate a random patrol from a start node.

***

## 2. Vehicle Joining a Road

**Goal:** A car parked off-road drives to a destination on the network and parks somewhere off-road again.

{% stepper %}
{% step %}

### Use **OWP AI Move To** with **Target Location** = destination.

{% endstep %}

{% step %}

### Internally, OWP combines NavMesh entry → spline route → NavMesh exit (Free Pathfind).

{% endstep %}

{% step %}

### Set a higher **Step Distance** (400–600) for vehicles.

{% endstep %}

{% step %}

### Make sure your level has a NavMesh covering the parking lots and surrounding area.

{% endstep %}
{% endstepper %}

**Tip:** For tight road behavior (no swerving), set vehicle paths' **Path Width** = 0.

***

## 3. Faction-Restricted Path

**Goal:** Friendly factions can use this path; hostile factions can't.

{% stepper %}
{% step %}

### Add a **Require Tag** condition on the path.

{% endstep %}

{% step %}

### Set **Required Tag** = `Faction.Friendly`.

{% endstep %}

{% step %}

### In your AI controller, ensure the pawn's tags include `Faction.Friendly` or `Faction.Hostile`.

{% endstep %}

{% step %}

### The pathfinder automatically excludes the path for hostile travelers.

{% endstep %}
{% endstepper %}

**Variation: hostile pays cost penalty instead of being blocked.** Create a custom condition whose **Get Cost Modifier** returns 1.0 for friendly and 5.0 for hostile.

***

## 4. Save & Load

**Goal:** Persist runtime-spawned nodes and any tweaks across sessions.

{% stepper %}
{% step %}

### Create a USaveGame Blueprint with one variable: **OWP Snapshot** (type: `OWP Network Snapshot`).

{% endstep %}

{% step %}

### On save:

* Set the snapshot variable: **Save Network Snapshot** → into the variable.
* **Save Game To Slot** with your save object.
  {% endstep %}

{% step %}

### On load:

* **Load Game From Slot**.
* Read the snapshot variable.
* Call **Load Network Snapshot**.
  {% endstep %}
  {% endstepper %}

**Tip:** Always pass an explicit name when spawning runtime nodes — auto-generated names break load reliability.

***

## 5. Dynamic Roadblock

**Goal:** Close a road during a quest, reopen later.

### Option A — Toggle a Blocked Zone

{% stepper %}
{% step %}

### Place a **Blocked Zone** over the segment.

{% endstep %}

{% step %}

### Set **Is Active** = false initially.

{% endstep %}

{% step %}

### When the quest blocks it: set **Is Active** = true.

{% endstep %}

{% step %}

### Reopen: set **Is Active** = false.

{% endstep %}

{% step %}

### AI re-routes automatically the next time they request a path.

{% endstep %}
{% endstepper %}

### Option B — Disable the path itself

{% stepper %}
{% step %}

### Set the path's **Enabled** = false.

{% endstep %}

{% step %}

### AI re-routes automatically.

{% endstep %}
{% endstepper %}

**Tip:** Option A is better when you want to block a region (multiple paths). Option B is better for one specific path.

***

## 6. Group of AI Avoiding a Combat Zone

**Goal:** Patrolling guards avoid a danger area but assault troops accept the risk.

{% stepper %}
{% step %}

### Place a **Danger Zone** over the combat area.

{% endstep %}

{% step %}

### The default Cost Multiplier (×3) makes patrols re-route.

{% endstep %}

{% step %}

### For combat troops, you'd want them to **prefer** the zone — implement via a custom condition that reads the traveler's tag and returns negative cost (more attractive) for combat AI.

{% endstep %}
{% endstepper %}

***

## 7. Periodic Re-Path for Moving Target

**Goal:** AI chases a moving player without re-pathing every frame.

{% stepper %}
{% step %}

### Use a Behavior Tree.

{% endstep %}

{% step %}

### Add a **Service** that runs every 2 seconds.

{% endstep %}

{% step %}

### The Service updates the target blackboard key to the player's current location.

{% endstep %}

{% step %}

### The **OWP Move To** task reads the updated target and re-routes when it differs.

{% endstep %}
{% endstepper %}

This avoids the cost of pathfinding every frame while keeping the AI roughly accurate.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://onesteppack.gitbook.io/openworldnavigation-doc/07-recipes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
