Saving as Unity Asset

DSL Forge supports saving scripts as .txt files or ScriptableObject Assets. It supports import/export both ways:

  • Import external text into an Asset

  • Export Asset content to a readable text file

This makes it easy to version, share, and collaborate in a team.

Example: Create and Save a New DSLScriptAsset

// Create and save a new DSLScriptAsset
var asset = ScriptableObject.CreateInstance<DSLScriptAsset>();
asset.scriptText = "@Init\nLog(\"Hello from DSL Forge!\")";
AssetDatabase.CreateAsset(asset, "Assets/MyDSLScript.asset");
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
  • scriptText stores the DSL script as plain text

  • CreateAsset writes a .asset file to your project for easy version control


Example: Load DSL Script from an Existing Asset

var loadedAsset = AssetDatabase.LoadAssetAtPath<DSLScriptAsset>("Assets/MyDSLScript.asset");
string script = loadedAsset.scriptText;
Debug.Log("Loaded DSL script:\n" + script);
  • Works in both the Editor and at runtime

  • Integrates seamlessly with the visual editor for .txt ↔ Asset import/export

Last updated