API Reference
Complete reference for the StoryFlow Unity plugin API. This page covers all public classes, structs, interfaces, enums, events, and methods available in the StoryFlow.Runtime assembly.
Reading This Reference
All types in this reference are in the StoryFlow, StoryFlow.Data, StoryFlow.UI, or StoryFlow.Utilities namespaces. Inspector fields are shown as properties. C# events use the standard event Action pattern and can be subscribed to with +=. UnityEvents can be wired up in the Inspector.
StoryFlowManager
MonoBehaviour, Singleton - Manages shared state across all StoryFlowComponent instances. Persists across scene loads via DontDestroyOnLoad. Auto-creates itself at runtime when first accessed - no manual setup required. Automatically discovers the project asset in your project.
Properties
Instance StoryFlowManager static The singleton instance. Auto-creates a new manager GameObject if one does not already exist.
Project StoryFlowProjectAsset The project asset containing scripts, characters, and global variables. Assign in the Inspector or set at runtime via SetProject().
Methods
| Method | Returns | Description |
|---|---|---|
| Project | ||
SetProject(StoryFlowProjectAsset project) | void | Assigns a new project asset and reinitializes all shared state (global variables, characters, once-only options). |
GetProject() | StoryFlowProjectAsset | Returns the current project asset, or null if none is set. |
HasProject() | bool | Returns true if a project asset has been assigned. |
GetScript(string path) | StoryFlowScriptAsset | Gets a script asset by its path from the current project. Returns null if not found. |
GetAllScriptPaths() | List<string> | Returns a list of all script paths registered in the current project. |
| Save & Load | ||
SaveToSlot(string slotName) | bool | Saves global variables, runtime characters, and once-only options to the named slot. Returns true on success. |
LoadFromSlot(string slotName) | bool | Loads global state from the named slot. Fails if dialogue is active. Returns true on success. |
DoesSaveExist(string slotName) | bool | Returns true if a save exists at the specified slot. |
DeleteSave(string slotName) | void | Deletes the save at the specified slot, if it exists. |
| Reset | ||
ResetGlobalVariables() | void | Re-initializes global variables from the project asset, discarding runtime changes. |
ResetRuntimeCharacters() | void | Re-initializes runtime character data from the project asset, discarding runtime changes. |
ResetAllState() | void | Resets global variables, runtime characters, and once-only option tracking to project defaults. |
| Dialogue Tracking | ||
NotifyDialogueStarted() | void | Called by StoryFlowComponent when a dialogue session starts. Increments the active dialogue count. |
NotifyDialogueEnded() | void | Called by StoryFlowComponent when a dialogue session ends. Decrements the active dialogue count. |
IsDialogueActive() | bool | Returns true if any StoryFlowComponent currently has an active dialogue. |
// Example: manager setup and save/load
var manager = StoryFlowManager.Instance;
manager.SetProject(myProjectAsset);
// Save state after dialogue completes
manager.SaveToSlot("autosave");
// Load state later (ensure no dialogue is active)
if (manager.DoesSaveExist("autosave"))
{
manager.LoadFromSlot("autosave");
} StoryFlowComponent
MonoBehaviour - The core runtime component that drives dialogue execution. Add it to any GameObject that needs to run StoryFlow dialogue. Decorated with [DisallowMultipleComponent].
Properties
Script StoryFlowScriptAsset Reference to the script asset to run when StartDialogue() is called with no arguments. If not assigned, falls back to the project's startup script.
LanguageCode string default: "en" Language code for localized string lookup (e.g., "en", "fr", "ja").
DialogueUI StoryFlowDialogueUI Optional dialogue UI handler. If set, the component automatically binds to it and sends dialogue state updates. If left empty, a built-in fallback UI is auto-created at runtime — the layout is selected via UIStyle below. To handle UI yourself by subscribing to the component's C# events, leave this empty and set UIStyle to None so the fallback is skipped.
UIStyle BuiltInUIStyle default: Default Built-in UI style used when DialogueUI is not assigned. Default embeds the portrait inside the dialogue panel; Portrait (added in v1.1.0) uses a detached SpriteRenderer portrait; None skips the fallback entirely so you can handle rendering yourself via C# events. See the BuiltInUIStyle enum below.
TraceEnabled bool default: true header: Debugging Enables execution trace logging with the [SF-TRACE] prefix for node processing, edge traversal, variable changes, and script calls. The trace format matches the Unreal and Godot plugins so logs can be diffed across runtimes. Disable in release builds to reduce log volume.
StopAudioOnDialogueEnd bool default: true When enabled, stops any playing dialogue audio when the dialogue session ends.
DialogueAudioMixerGroup AudioMixerGroup Audio mixer group for dialogue audio playback. Assign to route dialogue audio through your game's audio mix.
DialogueVolumeMultiplier float default: 1.0, range: 0-2 Volume multiplier applied to all dialogue audio playback.
Events
StoryFlowComponent provides both standard C# events (for code subscriptions via +=) and Inspector-assignable UnityEvent fields for the most common events.
C# Events
| Event | Signature | Description |
|---|---|---|
OnDialogueStarted | Action | Fired when a dialogue session starts. |
OnDialogueUpdated | Action<StoryFlowDialogueState> | Fired when the dialogue state changes (new node, text re-render, etc.). |
OnDialogueEnded | Action | Fired when the dialogue session ends. |
OnVariableChanged | Action<StoryFlowVariable, bool> | Fired when a variable value changes. The bool parameter indicates whether the variable is global. |
OnCharacterVariableChanged | Action<string, string, StoryFlowVariant> | Fired when a character variable is mutated. Payload (characterPath, variableName, value). Fires for built-in Name and Image mutations as well as custom character variables. The existing OnVariableChanged still fires for character mutations but does not carry the character path, so this new event is recommended for character-scoped reactions. |
OnScriptStarted | Action<string> | Fired when execution enters a new script via RunScript. Parameter: script path. |
OnScriptEnded | Action<string> | Fired when execution returns from a RunScript call. Parameter: script path. |
OnError | Action<string> | Fired when an execution error occurs. Parameter: error message. |
OnBackgroundImageChanged | Action<Sprite> | Fired when a SetBackgroundImage node sets a new background. |
OnAudioPlayRequested | Action<AudioClip, bool> | Fired when a PlayAudio node requests audio playback. The bool indicates looping. |
UnityEvents (Inspector-assignable)
| Event | Type | Description |
|---|---|---|
OnDialogueStartedEvent | UnityEvent | Inspector-assignable version of OnDialogueStarted. |
OnDialogueUpdatedEvent | UnityEvent<StoryFlowDialogueState> | Inspector-assignable version of OnDialogueUpdated. |
OnDialogueEndedEvent | UnityEvent | Inspector-assignable version of OnDialogueEnded. |
Methods
| Method | Returns | Description |
|---|---|---|
| Dialogue Control | ||
StartDialogue() | void | Starts dialogue using the configured Script asset, or the project's startup script if Script is not assigned. |
StartDialogue(string scriptPath) | void | Starts dialogue with the specified script path, overriding the Script property. |
StartDialogue(StoryFlowScriptAsset script) | void | Starts dialogue with a direct reference to a script asset. |
SelectOption(string optionId) | void | Selects a dialogue option by its ID. Advances execution along the chosen path. Marks once-only options as used. |
AdvanceDialogue() | void | Advances a narrative-only dialogue node (no options). Only works when CanAdvance is true. |
StopDialogue() | void | Immediately stops dialogue execution. Fires OnDialogueEnded. Stops audio if StopAudioOnDialogueEnd is enabled. |
PauseDialogue() | void | Pauses dialogue execution. State is preserved; no further events fire until resumed. |
ResumeDialogue() | void | Resumes a paused dialogue. Execution continues from where it was paused. |
PauseExecution() | void | Pauses node execution after the current node completes. The next node is held until ResumeExecution(). |
ResumeExecution() | void | Resumes execution from where it was paused by PauseExecution(). |
PauseExecutionFor(float seconds) | Coroutine | Pauses execution for the given duration, then resumes automatically. Returns the coroutine handle. |
| State Access | ||
GetCurrentDialogue() | StoryFlowDialogueState | Returns the current dialogue state, or null if no dialogue is active. |
IsDialogueActive() | bool | Returns true if a dialogue session is currently active. |
IsWaitingForInput() | bool | Returns true if the dialogue is currently waiting for player input. |
IsPaused() | bool | Returns true if the dialogue is currently paused. |
GetProject() | StoryFlowProjectAsset | Returns the effective project asset from StoryFlowManager.Instance.Project. |
| Variable Access | ||
GetBoolVariable(string name, bool global = false) | bool | Gets a boolean variable by display name. When global is false, searches local scope first. |
SetBoolVariable(string name, bool value, bool global = false) | void | Sets a boolean variable by display name. Fires OnVariableChanged. |
GetIntVariable(string name, bool global = false) | int | Gets an integer variable by display name. |
SetIntVariable(string name, int value, bool global = false) | void | Sets an integer variable by display name. Fires OnVariableChanged. |
GetFloatVariable(string name, bool global = false) | float | Gets a float variable by display name. |
SetFloatVariable(string name, float value, bool global = false) | void | Sets a float variable by display name. Fires OnVariableChanged. |
GetStringVariable(string name, bool global = false) | string | Gets a string variable by display name. The value is resolved through the project's string table automatically, so the return is the actual display text rather than an internal key like str_0. |
SetStringVariable(string name, string value, bool global = false) | void | Sets a string variable by display name. Fires OnVariableChanged. |
GetEnumVariable(string name, bool global = false) | string | Gets an enum variable by display name. Returns the current enum value as a string. |
SetEnumVariable(string name, string value, bool global = false) | void | Sets an enum variable by display name. Fires OnVariableChanged. |
GetArrayVariable(string name, bool global = false) | List<StoryFlowVariant> | Gets an array variable by display name. Works for any array type (string, int, float, bool, enum, etc.). String and enum values are resolved through the string table automatically. |
SetBoolArrayVariable(string variableName, List<bool> values, bool global = false) | void | Replaces a boolean array variable's contents. Fires OnVariableChanged and re-renders the current dialogue so option visibility and text interpolation refresh automatically. |
SetIntArrayVariable(string variableName, List<int> values, bool global = false) | void | Replaces an integer array variable's contents. Fires OnVariableChanged and re-renders the current dialogue. |
SetFloatArrayVariable(string variableName, List<float> values, bool global = false) | void | Replaces a float array variable's contents. Fires OnVariableChanged and re-renders the current dialogue. |
SetStringArrayVariable(string variableName, List<string> values, bool global = false) | void | Replaces a string array variable's contents. Fires OnVariableChanged and re-renders the current dialogue. |
SetEnumArrayVariable(string variableName, List<string> values, bool global = false) | void | Replaces an enum array variable's contents. Fires OnVariableChanged and re-renders the current dialogue. |
SetImageArrayVariable(string variableName, List<string> assetKeys, bool global = false) | void | Replaces an image array variable's contents with a list of asset keys. Fires OnVariableChanged and re-renders the current dialogue. |
SetAudioArrayVariable(string variableName, List<string> assetKeys, bool global = false) | void | Replaces an audio array variable's contents with a list of asset keys. Fires OnVariableChanged and re-renders the current dialogue. |
SetCharacterArrayVariable(string variableName, List<string> characterPaths, bool global = false) | void | Replaces a character array variable's contents with a list of character paths. Fires OnVariableChanged and re-renders the current dialogue. |
AddBoolArrayElement(string variableName, bool value, bool global = false) | void | Appends a single element to a boolean array variable, matching the in-graph addTo*Array node semantics. Initializes the underlying list when called on a fresh variable. Fires OnVariableChanged. |
AddIntArrayElement(string variableName, int value, bool global = false) | void | Appends a single element to an integer array variable. Fires OnVariableChanged. |
AddFloatArrayElement(string variableName, float value, bool global = false) | void | Appends a single element to a float array variable. Fires OnVariableChanged. |
AddStringArrayElement(string variableName, string value, bool global = false) | void | Appends a single element to a string array variable. Fires OnVariableChanged. |
AddEnumArrayElement(string variableName, string value, bool global = false) | void | Appends a single element to an enum array variable. Fires OnVariableChanged. |
AddImageArrayElement(string variableName, string assetKey, bool global = false) | void | Appends a single asset key to an image array variable. Fires OnVariableChanged. |
AddAudioArrayElement(string variableName, string assetKey, bool global = false) | void | Appends a single asset key to an audio array variable. Fires OnVariableChanged. |
AddCharacterArrayElement(string variableName, string characterPath, bool global = false) | void | Appends a single character path to a character array variable. Fires OnVariableChanged. |
GetMapVariable(string name, bool global = false) | List<StoryFlowMapEntry> | Added in v1.2.0. Gets a map variable's entries by display name, in insertion order. String, enum, image, audio and character values are resolved through the string table automatically while keys stay raw. The returned entries are deep copies, never the live storage, so game code cannot corrupt aliased map variables. Returns an empty list if the variable is missing or is not a map. |
GetStringToBoolMap(string variableName, bool global = false) | Dictionary<string, bool> | Added in v1.2.0. Reads a string-keyed (or enum-keyed), boolean-valued map as a native dictionary. Keys are returned raw. Logs a warning and returns an empty dictionary on a missing, non-map, or wrong key/value-type variable. The dictionary may not preserve insertion order - use GetMapKeysInOrder. |
GetStringToIntMap(string variableName, bool global = false) | Dictionary<string, int> | Added in v1.2.0. Reads a string/enum-keyed, integer-valued map as a native dictionary. Keys are raw. Empty dictionary with a warning on type mismatch. Order is not guaranteed - use GetMapKeysInOrder. |
GetStringToFloatMap(string variableName, bool global = false) | Dictionary<string, float> | Added in v1.2.0. Reads a string/enum-keyed, float-valued map as a native dictionary. Keys are raw. Empty dictionary with a warning on type mismatch. Order is not guaranteed - use GetMapKeysInOrder. |
GetStringToStringMap(string variableName, bool global = false) | Dictionary<string, string> | Added in v1.2.0. Reads a string/enum-keyed map whose values are string-family (string, enum, image, audio, or character) as a native dictionary. String and enum values are resolved through the string table; image, audio and character values are returned raw (asset keys / character paths). Keys are raw. Order is not guaranteed - use GetMapKeysInOrder. |
GetIntToBoolMap(string variableName, bool global = false) | Dictionary<int, bool> | Added in v1.2.0. Reads an integer-keyed, boolean-valued map as a native dictionary. Empty dictionary with a warning on type mismatch. Order is not guaranteed - use GetMapKeysInOrder. |
GetIntToIntMap(string variableName, bool global = false) | Dictionary<int, int> | Added in v1.2.0. Reads an integer-keyed, integer-valued map as a native dictionary. Empty dictionary with a warning on type mismatch. Order is not guaranteed - use GetMapKeysInOrder. |
GetIntToFloatMap(string variableName, bool global = false) | Dictionary<int, float> | Added in v1.2.0. Reads an integer-keyed, float-valued map as a native dictionary. Empty dictionary with a warning on type mismatch. Order is not guaranteed - use GetMapKeysInOrder. |
GetIntToStringMap(string variableName, bool global = false) | Dictionary<int, string> | Added in v1.2.0. Reads an integer-keyed map whose values are string-family (string, enum, image, audio, or character) as a native dictionary. String and enum values are resolved through the string table; image, audio and character values are returned raw. Order is not guaranteed - use GetMapKeysInOrder. |
GetMapKeysInOrder(string variableName, bool global = false) | List<string> | Added in v1.2.0. Returns a map's keys in the contractual insertion order (matching the editor and the mapKeys / forEachMap projection). String and enum keys come back verbatim; integer keys are stringified via int.ToString(). This is the ordered escape hatch for the typed Get*Map getters, whose dictionary view does not preserve order. Logs a warning and returns an empty list on a missing or non-map variable. |
SetStringToBoolMap(string variableName, Dictionary<string, bool> values, bool global = false) | void | Added in v1.2.0. Replaces a string-keyed (or enum-keyed), boolean-valued map's entries from a dictionary, stored in the dictionary's enumeration order. A null dictionary clears the map. Fires OnVariableChanged and re-renders the current dialogue. Warns and no-ops on a missing, non-map, or wrong key/value-type variable. |
SetStringToIntMap(string variableName, Dictionary<string, int> values, bool global = false) | void | Added in v1.2.0. Replaces a string/enum-keyed, integer-valued map's entries from a dictionary. A null dictionary clears the map. Fires OnVariableChanged and re-renders the current dialogue. |
SetStringToFloatMap(string variableName, Dictionary<string, float> values, bool global = false) | void | Added in v1.2.0. Replaces a string/enum-keyed, float-valued map's entries from a dictionary. A null dictionary clears the map. Fires OnVariableChanged and re-renders the current dialogue. |
SetStringToStringMap(string variableName, Dictionary<string, string> values, bool global = false) | void | Added in v1.2.0. Replaces a string/enum-keyed map whose values are string-family (string, enum, image, audio, or character) from a dictionary. For string and enum values, pass strings-table keys to keep them translatable; raw display text bypasses the table. Image, audio and character values are asset keys / character paths. Fires OnVariableChanged and re-renders the current dialogue. |
SetIntToBoolMap(string variableName, Dictionary<int, bool> values, bool global = false) | void | Added in v1.2.0. Replaces an integer-keyed, boolean-valued map's entries from a dictionary. A null dictionary clears the map. Fires OnVariableChanged and re-renders the current dialogue. |
SetIntToIntMap(string variableName, Dictionary<int, int> values, bool global = false) | void | Added in v1.2.0. Replaces an integer-keyed, integer-valued map's entries from a dictionary. A null dictionary clears the map. Fires OnVariableChanged and re-renders the current dialogue. |
SetIntToFloatMap(string variableName, Dictionary<int, float> values, bool global = false) | void | Added in v1.2.0. Replaces an integer-keyed, float-valued map's entries from a dictionary. A null dictionary clears the map. Fires OnVariableChanged and re-renders the current dialogue. |
SetIntToStringMap(string variableName, Dictionary<int, string> values, bool global = false) | void | Added in v1.2.0. Replaces an integer-keyed map whose values are string-family (string, enum, image, audio, or character) from a dictionary. String and enum values follow the same strings-table rule as SetStringToStringMap. Fires OnVariableChanged and re-renders the current dialogue. |
GetCharacterVariable(string charPath, string varName) | StoryFlowVariant | Gets a character variable value by character path and variable name. Reads from runtime character data. The names "Name" and "Image" are recognized as case-insensitive special cases: Name returns the resolved display string and Image returns the current ImageAssetKey. Both are always available even when the character has no custom variables. |
SetCharacterVariable(string charPath, string varName, StoryFlowVariant value) | void | Sets a character variable value. Mutates runtime character data, not the source asset. |
GetCharacter(string characterPath) | StoryFlowCharacterData | Returns the live runtime character data for a path, or null if no character is registered there. |
GetCharacterVariables(string characterPath) | List<string> | Returns the names of the custom variables defined on a character. Excludes the built-in Name and Image fields, which are always reachable through GetCharacterVariable. |
GetCharacterArrayVariable(string variableName) | List<string> | Reads a script or global variable whose element type is character, returning a list of character paths. Distinct from GetCharacterVariable, which reads a variable that lives on a single character. |
GetCharacterPortrait(string characterPath, string assetKey = "") | Sprite | Resolves a character portrait through the character then script then project asset cascade. An empty assetKey uses the character's current ImageAssetKey, which reflects any setCharacterVar mutations on the Image field. Returns a Sprite for direct UGUI compatibility. |
ResetVariables() | void | Clears cached node states and re-initializes local variables from the current script asset. |
| Localization & Assets | ||
GetLocalizedString(string key) | string | Looks up a localized string using the component's LanguageCode. |
ResolveAsset<T>(string assetKey) | T | Resolves a Unity asset by key. Checks the current script's resolved assets first, then the project's. T must extend UnityEngine.Object. |
| Input Options | ||
InputChanged(string optionId, string value) | void | Reports a string input change for a dialogue input option. Wraps the value and delegates to the typed overload. |
InputChanged(string optionId, StoryFlowVariant value) | void | Reports a typed input change. Stores the value, re-interpolates dialogue text, broadcasts the update, and follows the option's "on change" edge if one exists. |
| Audio | ||
PlayDialogueAudio(AudioClip clip, bool loop) | void | Plays a dialogue audio clip. Creates an AudioSource on demand. Stops any currently playing dialogue audio first. |
StopDialogueAudio() | void | Stops the dialogue audio source if it is currently playing. |
IsDialogueAudioPlaying() | bool | Returns true if dialogue audio is currently playing. |
SetAudioAdvanceState(bool waiting, bool allowSkip) | void | Controls the audio-advance gate. When waiting is true, the component polls for audio completion and auto-advances. allowSkip determines if manual advance is allowed before audio finishes. |
// Example: subscribing to events and controlling dialogue
var storyFlow = GetComponent<StoryFlowComponent>();
storyFlow.OnDialogueStarted += () => Debug.Log("Dialogue started");
storyFlow.OnDialogueUpdated += (state) =>
{
Debug.Log($"Speaker: {state.Character?.Name}, Text: {state.Text}");
foreach (var option in state.Options)
Debug.Log($" Option: {option.Text} (id: {option.Id})");
};
storyFlow.OnDialogueEnded += () => Debug.Log("Dialogue ended");
storyFlow.OnError += (msg) => Debug.LogError($"StoryFlow error: {msg}");
// Start the dialogue
storyFlow.StartDialogue();
// Later, when the player selects an option:
storyFlow.SelectOption(selectedOptionId);
// Or advance narrative text:
storyFlow.AdvanceDialogue(); // Example: typed map access as native dictionaries
var storyFlow = GetComponent<StoryFlowComponent>();
// Read a string-keyed, int-valued map
Dictionary<string, int> stats = storyFlow.GetStringToIntMap("playerStats", global: true);
int strength = stats.TryGetValue("strength", out var s) ? s : 0;
stats["strength"] = strength + 1;
// Write the whole dictionary back (fires OnVariableChanged, re-renders dialogue)
storyFlow.SetStringToIntMap("playerStats", stats, global: true);
// Dictionary order is not guaranteed - walk keys in authoritative insertion order
foreach (string key in storyFlow.GetMapKeysInOrder("playerStats", global: true))
Debug.Log($"{key}: {stats[key]}"); StoryFlowDialogueState
[Serializable] class - Namespace: StoryFlow.Data - Represents the current state of a dialogue node. Passed to OnDialogueUpdated listeners and returned by GetCurrentDialogue().
| Name | Type | Description |
|---|---|---|
NodeId | string | The unique ID of the dialogue node in the script graph. |
Title | string | Optional title text for the dialogue node. |
Text | string | The interpolated dialogue text with all {varname} placeholders resolved. |
Image | Sprite | The resolved image sprite for the dialogue node, or null. |
Audio | AudioClip | The resolved audio clip for the dialogue node, or null. |
Character | StoryFlowCharacterData | The resolved character data for the dialogue node. Contains name, portrait, and variables. |
TextBlocks | List<StoryFlowTextBlock> | Segmented text blocks for advanced rendering. Each block has an Id and Text. |
Options | List<StoryFlowOption> | The list of dialogue options available to the player. |
IsValid | bool | Whether this dialogue state contains valid data for rendering. |
CanAdvance | bool | true if the dialogue has a default output edge and no options - the player can click "continue" to advance. |
AudioLoop | bool | Whether dialogue audio should loop continuously. |
AudioReset | bool | Whether to stop previous audio when this dialogue has no audio assigned. |
AudioAdvanceOnEnd | bool | Whether the dialogue should auto-advance when its audio clip finishes playing. |
AudioAllowSkip | bool | Whether the player can manually advance past the audio-gated wait. |
StoryFlowOption
| Name | Type | Description |
|---|---|---|
Id | string | Unique identifier for this option. Pass to SelectOption(). |
Text | string | Display text for the option (interpolated). |
IsOnceOnly | bool | If true, this option disappears after being selected once (tracked across the session). |
IsSelected | bool | Reserved field. Currently not populated by the runtime (always false). |
InputType | string | For input options: the type of input ("string", "integer", "float", "boolean", "enum"). Empty for regular button options. |
DefaultValue | string | The default value for input options. |
StoryFlowTextBlock
| Name | Type | Description |
|---|---|---|
Id | string | Unique identifier for the text block. |
Text | string | The interpolated text content of this block. |
StoryFlowVariable
[Serializable] class - Namespace: StoryFlow.Data - Represents a single variable in a StoryFlow project. Used for both local (script-scoped) and global variables.
| Name | Type | Description |
|---|---|---|
Id | string | Unique identifier for the variable (matches the editor's internal ID). |
Name | string | Display name of the variable. Used by the Get/SetXxxVariable methods on StoryFlowComponent. |
Type | StoryFlowVariableType | The data type of this variable (Boolean, Integer, Float, String, Enum, Image, Audio, Character, Map). |
Value | StoryFlowVariant | The current typed value of the variable. |
IsArray | bool | Whether this variable is an array type. |
EnumValues | List<string> | For enum variables: the list of allowed enum values. |
IsInput | bool | Whether this variable is marked as an input parameter for the script. |
IsOutput | bool | Whether this variable is marked as an output parameter for the script. |
StoryFlowVariant
[Serializable] class - Namespace: StoryFlow.Data - A polymorphic value container that holds a single typed value. Used as the Value field on StoryFlowVariable and for character variables.
Properties
| Name | Type | Description |
|---|---|---|
Type | StoryFlowVariableType | The active type of this variant. |
BoolValue | bool | The boolean value (valid when Type == Boolean). |
IntValue | int | The integer value (valid when Type == Integer). |
FloatValue | float | The float value (valid when Type == Float). |
StringValue | string | The string value (valid when Type == String). Also used for Image, Audio, and Character asset keys. |
EnumValue | string | The enum value as a string (valid when Type == Enum). |
ArrayValue | List<StoryFlowVariant> | The array value for array-typed variables. |
MapValue | List<StoryFlowMapEntry> | The map entries for map-typed variables, in insertion order. Marked [NonSerialized], like ArrayValue. Added in v1.2.0. |
Getters
| Method | Returns | Description |
|---|---|---|
GetBool(bool defaultValue = false) | bool | Returns BoolValue if type is Boolean, otherwise defaultValue. |
GetInt(int defaultValue = 0) | int | Returns IntValue if type is Integer, otherwise defaultValue. |
GetFloat(float defaultValue = 0f) | float | Returns FloatValue if type is Float, otherwise defaultValue. |
GetString(string defaultValue = "") | string | Returns StringValue if type is String, otherwise defaultValue. |
GetEnum(string defaultValue = "") | string | Returns EnumValue if type is Enum, otherwise defaultValue. |
GetArray() | List<StoryFlowVariant> | Returns the array value, creating an empty list if null. |
GetMap() | List<StoryFlowMapEntry> | Returns the map entries, creating an empty list if null. Added in v1.2.0. |
Setters
| Method | Description |
|---|---|
SetBool(bool value) | Sets type to Boolean and stores the value. |
SetInt(int value) | Sets type to Integer and stores the value. |
SetFloat(float value) | Sets type to Float and stores the value. |
SetString(string value) | Sets type to String and stores the value. |
SetEnum(string value) | Sets type to Enum and stores the value. |
SetMap(List<StoryFlowMapEntry> entries) | Sets type to Map and stores the entries (an empty list if null). A variant holds either array or map data, never both, so the array storage is cleared. Added in v1.2.0. |
Reset() | Resets all value fields to their defaults (false, 0, "", null). |
Static Factory Methods
| Method | Returns | Description |
|---|---|---|
StoryFlowVariant.Bool(bool value) | StoryFlowVariant | Creates a Boolean variant. |
StoryFlowVariant.Int(int value) | StoryFlowVariant | Creates an Integer variant. |
StoryFlowVariant.Float(float value) | StoryFlowVariant | Creates a Float variant. |
StoryFlowVariant.String(string value) | StoryFlowVariant | Creates a String variant. |
StoryFlowVariant.Enum(string value) | StoryFlowVariant | Creates an Enum variant. |
StoryFlowVariant.DeserializeFromJson(StoryFlowVariableType type, string json) | StoryFlowVariant | Deserializes a variant from a type and plain-text JSON value string. Used by importers and save/load. |
Other
| Method | Returns | Description |
|---|---|---|
ToString() | string | Returns a string representation of the active value based on its type. |
StoryFlowMapEntry
[Serializable] class - Namespace: StoryFlow.Data - A single key/value entry in a map variable. Added in v1.2.0. Map variables store their entries as List<StoryFlowMapEntry>, preserving insertion order. Returned by StoryFlowComponent.GetMapVariable and StoryFlowVariant.GetMap.
| Name | Type | Description |
|---|---|---|
Key | StoryFlowVariant | The entry's key. Call the typed getters (GetString(), GetInt(), etc.) to read it. Keys are raw identifiers and are never localized. |
Value | StoryFlowVariant | The entry's value. Call the typed getters to read it. String, enum, image, audio and character values returned by GetMapVariable are resolved through the string table. |
StoryFlowCharacterData
[Serializable] class - Namespace: StoryFlow.Data - Runtime character data resolved from the imported character definitions. Contains the character's name, portrait image, and per-character variables.
| Name | Type | Description |
|---|---|---|
Name | string | The display name of the character. |
ImageAssetKey | string | The asset key for the character's portrait image (before resolution). |
Image | Sprite | The character's portrait image, or null. |
Variables | Dictionary<string, StoryFlowVariant> | Quick-lookup dictionary of character variables keyed by name. |
VariablesList | List<StoryFlowVariable> | Full list of character variables with metadata. Used for save/load and mutation. |
Methods
| Method | Returns | Description |
|---|---|---|
FindVariableByName(string name) | StoryFlowVariable | Finds a variable in VariablesList by its display name. Returns null if not found. |
StoryFlowSettings
ScriptableObject - Namespace: StoryFlow.Data - Project-wide settings for the StoryFlow plugin. Create via Assets > Create > StoryFlow > Settings and place in a Resources/ folder named StoryFlowSettings.
| Name | Type | Description |
|---|---|---|
Instance | StoryFlowSettings | Static property. Returns the cached settings instance loaded from Resources/StoryFlowSettings. |
DefaultProject | StoryFlowProjectAsset | Default project asset to auto-load. Leave empty for manual loading. |
DefaultImportPath | string | Default output path for imported assets, relative to Assets/. Default: "StoryFlow". |
VerboseLogging | bool | Enable verbose logging for node execution. Logs every node that is processed. |
LogVariableChanges | bool | Log variable changes at runtime. Includes variable name, value, and scope in the log. |
Static Methods
| Method | Returns | Description |
|---|---|---|
SetInstance(StoryFlowSettings settings) | void | Explicitly sets the settings instance. Useful for testing or custom initialization. |
ClearCache() | void | Clears the cached instance, forcing a fresh lookup from Resources on next access. |
UI Classes
The plugin provides an interface and an abstract base class for building dialogue UIs. You can choose whichever approach fits your project architecture.
IStoryFlowDialogueUI
interface - Namespace: StoryFlow.UI - Implement this when your class already extends another MonoBehaviour base and cannot inherit from StoryFlowDialogueUI. You must manually subscribe to events on StoryFlowComponent.
| Method | Parameters | Description |
|---|---|---|
OnDialogueStarted() | - | Called when dialogue execution begins. |
HandleDialogueUpdated(StoryFlowDialogueState state) | state: the current dialogue state | Called whenever the dialogue state changes. Primary method for rendering dialogue content. |
OnDialogueEnded() | - | Called when dialogue execution finishes. |
OnVariableChanged(StoryFlowVariable variable, bool isGlobal) | variable: the changed variable, isGlobal: scope flag | Called when a variable changes value during execution. |
StoryFlowDialogueUI
abstract MonoBehaviour, implements IStoryFlowDialogueUI - Namespace: StoryFlow.UI - The recommended base class for dialogue UIs. Extend this and override the virtual methods. The component automatically subscribes to events when initialized.
Lifecycle
| Method | Description |
|---|---|
IsBoundTo(StoryFlowComponent component) | Returns true if this UI is already bound to the given component. |
InitializeWithComponent(StoryFlowComponent component) | Binds this UI to a component, subscribing to all dialogue events. Called automatically if assigned to the component's DialogueUI field. |
Virtual Methods (Override These)
| Method | Description |
|---|---|
OnDialogueStarted() | Called when dialogue starts. Show your UI panel here. |
HandleDialogueUpdated(StoryFlowDialogueState state) | Called on every dialogue state change. Update text, options, character portrait, etc. |
OnDialogueEnded() | Called when dialogue ends. Hide your UI panel here. |
OnVariableChanged(StoryFlowVariable variable, bool isGlobal) | Called when a variable changes. Useful for reactive UI elements. |
OnBackgroundImageChanged(Sprite backgroundImage) | Called when a SetBackgroundImage node changes the persistent background. |
Convenience Methods
| Method | Returns | Description |
|---|---|---|
SelectOption(string optionId) | void | Forwards to storyFlowComponent.SelectOption(). Call from your UI button handlers. |
AdvanceDialogue() | void | Forwards to storyFlowComponent.AdvanceDialogue(). |
InputChanged(string optionId, string value) | void | Forwards to storyFlowComponent.InputChanged(). |
GetLocalizedString(string key) | string | Resolves a localized string using the component's language code. |
GetCurrentDialogue() | StoryFlowDialogueState | Gets the current dialogue state snapshot. |
IsDialogueActive() | bool | Returns true if dialogue is currently active on the bound component. |
// Example: custom dialogue UI
using StoryFlow.Data;
using StoryFlow.UI;
using UnityEngine;
using UnityEngine.UI;
public class MyDialogueUI : StoryFlowDialogueUI
{
[SerializeField] private Text nameText;
[SerializeField] private Text dialogueText;
[SerializeField] private GameObject optionsPanel;
[SerializeField] private Button continueButton;
[SerializeField] private GameObject panel;
public override void OnDialogueStarted()
{
panel.SetActive(true);
}
public override void HandleDialogueUpdated(StoryFlowDialogueState state)
{
nameText.text = state.Character?.Name ?? "";
dialogueText.text = state.Text;
// Show continue button or options
continueButton.gameObject.SetActive(state.CanAdvance);
optionsPanel.SetActive(state.Options.Count > 0);
// Build option buttons...
}
public override void OnDialogueEnded()
{
panel.SetActive(false);
}
} StoryFlowSaveHelpers
static class - Namespace: StoryFlow.Utilities - Low-level save/load utilities used internally by StoryFlowManager. Save files are stored at Application.persistentDataPath/StoryFlow/Saves/{slotName}.json.
| Member | Type / Returns | Description |
|---|---|---|
CurrentSaveVersion | string ("1.0.0") | Current save format version. Used for version compatibility checks on load. |
Save(string slotName, ...) | void | Serializes global variables, runtime characters, and once-only options to JSON and writes to disk. |
SaveAsync(string slotName, ...) | Task<bool> | Asynchronous variant of Save using non-blocking file I/O. Returns true on success. |
Load(string slotName) | StoryFlowSaveData | Reads and deserializes save data from the named slot. Returns null if the file does not exist. |
LoadAsync(string slotName) | Task<StoryFlowSaveData> | Asynchronous variant of Load. Returns null on failure. |
Exists(string slotName) | bool | Returns true if a save file exists at the named slot. |
Delete(string slotName) | void | Deletes the save file at the named slot, if it exists. |
Use StoryFlowManager Instead
For most use cases, call StoryFlowManager.SaveToSlot() and LoadFromSlot() instead of using StoryFlowSaveHelpers directly. The manager handles merging saved data back into the active runtime state.
StoryFlowNodeDispatcher
static class - Namespace: StoryFlow.Execution.NodeHandlers - The dispatch table that maps StoryFlowNodeType values to handler methods. Provides extension points for custom node types.
| Method | Returns | Description |
|---|---|---|
ProcessNode(StoryFlowComponent component, StoryFlowNode node) | void | Dispatches a node to the appropriate handler. Falls back to custom handlers if no built-in handler exists. |
RegisterHandler(StoryFlowNodeType type, Action<StoryFlowComponent, StoryFlowNode> handler) | void | Registers or overrides a handler for a built-in node type. |
UnregisterHandler(StoryFlowNodeType type) | bool | Removes a handler. Returns true if a handler was removed. |
HasHandler(StoryFlowNodeType type) | bool | Checks whether a handler is registered for the given node type. |
RegisterCustomHandler(string typeName, Action<StoryFlowComponent, StoryFlowNode> handler) | void | Registers a handler for a custom node type by string name. Use for node types not in the StoryFlowNodeType enum. |
UnregisterCustomHandler(string typeName) | bool | Unregisters a custom string-named handler. |
// Example: registering a custom node handler
StoryFlowNodeDispatcher.RegisterCustomHandler("myCustomNode",
(component, node) =>
{
Debug.Log($"Custom node executed: {node.Id}");
// Do your custom logic here, then advance to the next node:
// component.ProcessNextNodeFromSource(node.Id);
}); Enums
BuiltInUIStyle
Namespace: StoryFlow - Selects which built-in fallback UI is auto-created when a StoryFlowComponent has no DialogueUI assigned. Set via the UIStyle field on the component. Added in v1.1.0.
| Value | Description |
|---|---|
Default | Dark dialogue panel anchored to the bottom of the screen with the character portrait rendered inside the panel next to the name and body text. Instantiates StoryFlowRuntimeUI. |
Portrait | Large character portrait rendered as a detached SpriteRenderer anchored to the bottom center of the screen, with a smaller dialogue panel below. Instantiates StoryFlowRuntimeUIPortrait. Requires an orthographic camera because the portrait is world-space, not screen-space. |
None | No fallback UI is created. Use this when DialogueUI is left empty and you want to handle dialogue rendering yourself by subscribing to the component's C# events (OnDialogueStarted, OnDialogueUpdated, OnDialogueEnded, etc.). Has no effect if DialogueUI is assigned. |
StoryFlowVariableType
Namespace: StoryFlow.Data - Defines the data types available for StoryFlow variables.
| Value | Description |
|---|---|
Boolean | A true/false value. |
Integer | A whole number (int). |
Float | A floating-point number. |
String | A text string. |
Enum | A named option from a predefined list. |
Image | A reference to an image asset (Sprite). |
Audio | A reference to an audio asset (AudioClip). |
Character | A reference to a character definition. |
Map | An ordered collection of key/value entries. Added in v1.2.0. |
StoryFlowNodeType
Namespace: StoryFlow.Data - Defines all node types supported by the runtime. Organized into categories:
| Category | Values |
|---|---|
| Special | Unknown (= 0, default/fallback value) |
| Control Flow | Start, End, Branch, RunScript, RunFlow, EntryFlow |
| Dialogue | Dialogue |
| Boolean | GetBool, SetBool, AndBool, OrBool, NotBool, EqualBool |
| Integer | GetInt, SetInt, PlusInt, MinusInt, MultiplyInt, DivideInt, ModuloInt, RandomInt, GreaterInt, GreaterOrEqualInt, LessInt, LessOrEqualInt, EqualInt |
| Float | GetFloat, SetFloat, PlusFloat, MinusFloat, MultiplyFloat, DivideFloat, ModuloFloat, RandomFloat, GreaterFloat, GreaterOrEqualFloat, LessFloat, LessOrEqualFloat, EqualFloat |
| String | GetString, SetString, ConcatenateString, EqualString, ContainsString, ToUpperCase, ToLowerCase, LengthString |
| Enum | GetEnum, SetEnum, EqualEnum, SwitchOnEnum, RandomBranch |
| Type Conversions | IntToBoolean, FloatToBoolean, IntToString, FloatToString, StringToInt, StringToFloat, IntToFloat, FloatToInt, IntToEnum, BooleanToInt, BooleanToFloat, StringToEnum, EnumToString |
| Arrays | Full set of array operations for each type (Bool, Int, Float, String, Image, Character, Audio): Get*Array, Set*Array, Get*ArrayElement, Set*ArrayElement, GetRandom*ArrayElement, Add*ArrayElement, Remove*ArrayElement, Clear*Array, *ArrayLength, *ArrayContains, FindIn*Array, ForEach*Loop |
| Media | GetImage, SetImage, SetBackgroundImage, GetAudio, SetAudio, PlayAudio, GetCharacter, SetCharacter |
| Character Variables | GetCharacterVar, SetCharacterVar |
| Maps | GetMap, SetMap, GetMapValue, SetMapValue, HasMapKey, MapSize, MapKeys, MapValues, RemoveMapKey, ClearMap, ForEachMap (added in v1.2.0) |