# Run Flow Core from Code

Level: Intermediate

## Goal

Call a named Flow Core Entry from a small MonoBehaviour after you already have a graph bound to a scene `FlowCoreProcess`.

This page is for the point where Unity code needs to start a visual graph. If you are still learning the visual workflow, start with the no-code Hello World path first.

## Prerequisites

* Unity can compile scripts.
* FlowCore is installed and visible in menus.
* You can create a scene GameObject with `FlowCoreProcess`.
* You can create a Local `Blackboard` value and bind it to `Local Blackboards`.
* You understand that code should call a public process API, not internal runtime data.

## What You Will Build

You will create a graph with an `Entry` named `SayHello`. That Entry will run an `Action` node with `Log String`, reading the Local Blackboard key `Say`. A small MonoBehaviour will call the Entry when the scene starts.

The visible result is the same as the first tutorial: the Unity Console prints:

```
Hello Flow Core
```

## Steps

1. Build the scene binding first.
   * Create or select a GameObject.
   * Add `FlowCoreProcess`.
   * Assign a Flow Graph asset.
   * Add a `Blackboard` component to the same GameObject.
   * Add a `String` key named `Say` with the value `Hello Flow Core`.
   * Add that Blackboard to the process `Local Blackboards` list at index `0`.
2. Create the code entry point in the graph.
   * Open the graph in the Flow Graph editor.
   * Set Debug Context to the GameObject with the process.
   * Add an `Entry` node.
   * Set the Entry title to `SayHello`.
   * Add an `Action` node.
   * Connect the Entry output to the Action input.
3. Add the visible result.
   * Select the `Action` node.
   * Add `Log String` from `Debug/Value/String`.
   * Set the value source to `Blackboard`.
   * Set scope to `Local`.
   * Set index to `0`.
   * Set key to `Say`.
4. Add a MonoBehaviour caller.

   Create a script like this and attach it to a scene GameObject:

   ```csharp
   using UnityEngine;
   using TwoCatsCode.FlowCore;

   public sealed class FlowCoreEntryCaller : MonoBehaviour
   {
       [SerializeField] private FlowCoreProcess process;
       [SerializeField] private string entryTitle = "SayHello";

       private void Start()
       {
           if (process == null)
           {
               Debug.LogWarning("FlowCoreEntryCaller has no FlowCoreProcess.", this);
               return;
           }

           if (!process.ExecuteEnterByTitle(entryTitle))
           {
               Debug.LogWarning($"Flow Core Entry was not executed: {entryTitle}", this);
           }
       }
   }
   ```
5. Assign the process reference.
   * Select the GameObject with `FlowCoreEntryCaller`.
   * Drag the GameObject that owns `FlowCoreProcess` into the `process` field.
   * Keep `entryTitle` as `SayHello`.
6. Enter Play Mode.
   * Open the Unity Console.
   * Press Play.
   * Confirm that the Console prints `Hello Flow Core`.

## Expected result

* Unity code calls `FlowCoreProcess.ExecuteEnterByTitle("SayHello")`.
* Flow Core starts the `SayHello` Entry chain.
* The graph reads `LocalBlackboard[0]` key `Say`.
* The Console prints `Hello Flow Core`.

## When To Use Code Instead of a Trigger

Use code-triggered Entry execution when another system already owns the moment of activation. Examples include a quest system, dialogue system, network event, custom input layer, test harness, or non-Flow Core gameplay component.

Use a visual `Trigger` node when the activation is naturally authored in Flow Core, such as Unity lifecycle events, UI events, input routes, local signals, or graph-level event workflows.

For decoupled event publishing, use the runtime lifecycle documentation before choosing `FlowEventBus`. Direct Entry calls are easier to verify for the first code integration.

## Common mistakes

* Calling the Entry title before the process exists in the scene.
* Typing `Sayhello` or `Say Hello` when the Entry title is `SayHello`.
* Adding a `Trigger` node and expecting `ExecuteEnterByTitle` to call it. Code calls an `Entry`.
* Forgetting to assign the graph asset to `FlowCoreProcess`.
* Forgetting to bind the Local Blackboard to `Local Blackboards`.
* Reading the wrong Blackboard scope or index.
* Mutating Blackboard lists from a background thread. Runtime graph calls should be coordinated on Unity's main thread.

## Next steps

* [First 15 Minutes](/flow-core-docs/documentation/tutorials/first-15-minutes.md)
* [Run a Flow Graph in a Scene](/flow-core-docs/documentation/tutorials/run-a-flow-graph-in-a-scene.md)
* [Lifecycle and Dataflow](/flow-core-docs/documentation/runtime-guide/lifecycle-and-dataflow.md)
* [Extension Points](/flow-core-docs/documentation/api-extension-guide/extension-points.md)
* [Beginner Glossary](/flow-core-docs/documentation/reference/glossary.md)


---

# 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://flow-core.gitbook.io/flow-core-docs/documentation/getting-started/run-flow-core-from-code.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.
