Data Assets
Data Assets store reusable project data outside an individual dialogue script. Unity imports them with your StoryFlow Editor project so scripts and game code can read the same values.
Importing Data Assets
Create a .sfd file in the StoryFlow Editor, add variables and export or sync the project. The export includes data-assets.json and the assets referenced by Data Asset values. Import the complete export into Unity. See Importing Projects and Live Sync.
Find an imported asset by its stable ID or display name. IDs are safest because two assets can share a display name. An ambiguous name returns no match.
var manager = StoryFlowManager.Instance;
var quest = manager.FindDataAsset("Quest Settings");
if (quest == null) return; Reading and Writing Values
Pass the imported asset and a variable name to a typed accessor. The found output distinguishes a missing or mismatched value from a valid default such as false or 0. Setters return true when the write succeeds.
bool unlocked = manager.GetDataAssetBool(quest, "Unlocked", out bool found);
if (found && !unlocked)
{
manager.SetDataAssetBool(quest, "Unlocked", true);
}
int cost = manager.GetDataAssetInt(quest, "Cost", out found);
string title = manager.GetDataAssetString(quest, "Title", out found); Use GetDataAssetFloat, GetDataAssetEnum or GetDataAssetVariant for other declared types. The variant getter also reads arrays and maps. GetDataAssetVariableNames lists declared names, including inherited ones. These methods are also available on StoryFlowComponent when you want to use the component's project context.
Match the declared type
SetDataAssetString accepts string, image, audio and character values. Use SetDataAssetEnum for an enum declaration. A setter refuses a value that does not match the declaration.
Arrays and Maps
Replace a declared array or map with the container setters. An array takes a List<StoryFlowVariant>. A map takes parallel key and value lists. A type mismatch or unequal map list lengths refuses the whole write.
using System.Collections.Generic;
using StoryFlow.Data;
var reward = new StoryFlowVariant();
reward.SetInt(10);
bool changed = manager.SetDataAssetArrayVariable(
quest, "Rewards", new List<StoryFlowVariant> { reward });
var names = manager.GetDataAssetVariableNames(quest); For maps, call SetDataAssetMapVariable(asset, name, keys, values). Read either container through GetDataAssetVariant. See the API Reference for the complete method list.
Inheritance and Saves
A child Data Asset inherits declarations and values from its parent unless it overrides them. Reads use the nearest value in that chain. Runtime setters change the current session's value for the selected asset. They do not rewrite the source .sfd file.
Save runtime changes
Data Asset runtime changes are included in SaveToSlot and ExportState. Load a slot or import that state to restore them. See Save & Load.