# 3. Authoring Graphs and Custom Nodes
Part of [[Unity Behavior]]. Prev: [[2. BehaviorGraphAgent and the Blackboard]]. Next: [[4. C Sharp Bindings and Event Channels]].
## 3.1 Use the pre-built library first
The package ships a library of pre-built nodes (movement, detection, decision-making, as the 6000.5 package page describes). **Confirm the exact titles in the 1.0.17 Add menu.** This series does not invent a node named "Move To" or "Wait" as a C# API. If the library has a wait / sequence / condition that matches your policy, use it.
Build a first graph as a tree you can read aloud, top to bottom, in plain language. Official authoring is visual; keep C# for facts and for custom actions the library cannot express.
Subgraphs exist (official package feature). Use a subgraph when two enemies share an "investigate last point" chunk. Do not explode one graph into a second FSM in disguise.
## 3.2 Custom nodes: use the official wizard
If the library cannot express an action, official path: [Create a custom node](https://docs.unity3d.com/Packages/
[email protected]/manual/create-custom-node.html) (1.0.17). Do **not** hand-write a node class from memory and invent a `[NodeDescription]` constructor.
Official steps for a custom **Action** (the same wizard also creates Modifier and Sequencing nodes):
1. Right-click an empty area of the graph editor and choose **Create new**.
2. Choose **Action**.
3. Name the action in plain language (official example: `Agent runs away`). Optionally pick a category (official example: `Action/Move`).
4. Enter a **natural-language description**. Official: this determines how the node appears and what link fields it gets (example: `Agent runs away from the enemy and hides behind a tree for 2 seconds`).
5. Assign a type to each element. Official note: if a word matches an existing blackboard variable name, the wizard can assign that type automatically (example: `Target` as `GameObject`).
6. **Create.** Unity generates a C# script: the story as an attribute, link fields as blackboard variables, and empty overrides for **`OnStart`**, **`OnUpdate`**, and **`OnEnd`**. The class inherits `Action` (or Modifier / Composite), which extends official `Node`.
Implement those generated overrides. Official `Node` / `Action` API (1.0.17) also exposes members you may use from the generated class, including `GameObject` (the agent's GameObject) and `LogFailure`. Confirm return types and `Status` enum names in the **generated** file and in the 1.0.17 `Node` Scripting API — do not invent a `Status` value that the template does not already use.
The new type then appears under **Add > Action > [sub_category] > [new_node]**.
### Sequencing ports (official)
When you create a custom Sequencing node, the wizard can:
- Add **no** ports: the node accepts a dynamic number of children (official: identical in that respect to built-in **Try In Order** and **Random**). Use the inherited `Children` list in the generated script.
- Add **named** ports: each becomes a `public Node` field and a named connector. Official use: a fixed number of branches such as `OnSuccess` and `OnFailure`.
## 3.3 What not to do in a node
- Do not start a second `BehaviorGraphAgent` from inside a node "to nest behavior." Official subgraphs are the nesting tool.
- Do not `Destroy` the agent's GameObject in `OnStart` without also understanding shutdown (official: the agent stops and releases the instance when destroyed).
- Do not copy a generated script, change the class identity, and expect old graph assets to keep working (the wizard's attribute is how the graph finds the type; leave it alone unless you have read the 1.0.17 serialization / identity notes).
## 3.4 Exercise
Create a custom Action with the wizard whose story uses a blackboard `Target`. Open the generated script, log in `OnStart` / `OnEnd` using the official `GameObject` property, and drop the node into a tiny graph. Confirm it appears under the category you chose.
## Sources
- https://docs.unity3d.com/Packages/
[email protected]/manual/create-custom-node.html
- https://docs.unity3d.com/Packages/
[email protected]/api/Unity.Behavior.Action.html