UGTK / Toolkit / Utility Systems / Folder Path System Completed
Folder Path System
Summary
The Folder Path System solves "let the user pick a folder" twice over: a [FolderPath] attribute
that turns any string field into a text box with a … browse button in the inspector, and an
Mn_FolderPicker component that opens a real folder dialog at runtime — the native Windows
browser in a standalone build, Unity's own panel in the editor — reporting the result through
UnityEvents.
It is the piece you need for a kiosk that exports photos, a tool that writes a report, or any build that has to ask the operator where to save.
Content
Modules Dependencies
None. No UGTK reference. The runtime picker uses a P/Invoke into the Windows shell
(SHBrowseForFolder), which is bundled with the module.
Setup
There is no GIF for this module: every meaningful action opens an operating-system folder dialog, which is outside Unity and would put the machine's folder tree in the documentation.
- In the inspector: decorate a
stringfield with[FolderPath]. - At runtime: drop the
SelectFolderButtonprefab under a Canvas — a Button already wired toMn_FolderPicker.PickFolder()— or addMn_FolderPickerto a GameObject and bind the button yourself.
How To Use
The attribute
using UGTK.UtilitySystems.FolderPathSystem;
public class Exporter : MonoBehaviour
{
[FolderPath] public string outputFolder;
}
The drawer renders a normal text field plus a … button that opens
EditorUtility.OpenFolderPanel starting from Application.dataPath, and writes back the absolute
path. On a field that is not a string it draws a warning instead of the field — no silent failure.
The runtime component
- Folder Path: the current path, itself decorated with
[FolderPath], so you can also set it by hand from the inspector. - Dialog Title: the caption of the dialog.
- Create If Missing (default on): if the chosen folder no longer exists it is created.
- Events:
onFolderPicked(string),onCancelled,onError(string)in the inspector, plus the C# eventsFolderPicked,Cancelled,Errorfor code that wires itself.
folderPicker.PickFolder(); // 0 params: bind it straight to Button.onClick
folderPicker.SetFolder(path); // set from code (same validation and events)
folderPicker.ClearFolder(); // empties it
string current = folderPicker.FolderPath; // read-only property
Good to know:
- Platforms. In the editor (edit mode) it uses Unity's panel; in a Windows standalone build it
opens the native shell browser. On any other runtime platform — macOS, Linux, Android, WebGL —
it does not silently fail: it raises
onError. Handle that event, or the button will look broken. - Absolute paths, not asset paths. What you get back is a filesystem path
(
C:\Users\…\Documents\Export), notAssets/…: fine forSystem.IO, not usable withAssetDatabase. - Cancelling is not an error: closing the dialog fires
onCancelledand leaves the previous path untouched. - A path saved in the editor will not exist on another machine: treat the inspector value as a default, and let the operator pick at runtime.
Testing Scene
Open Debug/FolderPathScene.unity. It holds FolderPicker with Mn_FolderPicker — the
component itself — and FolderPath Example, which shows the same value being consumed. Everything
worth pressing is in the inspector's Editor Test Tools.
- Current folder shows the stored path and, under it, the answer that actually matters: whether the folder exists and is writable. A folder that exists but is read-only fails at save time, far away from the choice that caused it, so the check is here rather than there.
- Type a path into Path and press SetFolder(). With Create If Missing on, a folder that is not there yet is created, and the message flips to exists and is writable.
- Use persistentDataPath fills in Unity's own writable folder — the safe default on every platform.
- ClearFolder() forgets it.
PickFolder() opens the real Windows dialog and is the one control this scene cannot script:
it blocks the editor until you answer it. It is also Windows-only — on other platforms the component
says so and SetFolder is the way in.
One asymmetry worth knowing: SetFolder normalises the path and honours Create If Missing,
exactly as a pick does, but it deliberately does not raise onFolderPicked. Restoring a saved
preference at startup is not the user choosing a folder, and a listener that uploads or saves on
that event would fire on every launch.
Technical Info
| Path | Content |
|---|---|
Scripts/Attribute/FolderPathAttribute.cs |
Marker PropertyAttribute |
Scripts/Attribute/FolderPathDrawer.cs |
PropertyDrawer: text field + … button, with the string-type guard |
Scripts/Mn_FolderPicker.cs |
Runtime component: editor/native dialog, validation, folder creation, UnityEvents and C# events. Contains the WindowsNativeFolderPicker P/Invoke wrapper |
Prefabs/SelectFolderButton.prefab |
Button already wired to PickFolder() |
Debug/Mn_FolderPathExample.cs |
Minimal example of the attribute |
Debug/FolderPathScene.unity |
Test scene |
Mn_FolderPicker API: PickFolder(), SetFolder(string), ClearFolder(), FolderPath,
events onFolderPicked / onCancelled / onError and FolderPicked / Cancelled / Error.
© 2026 Marcello De Bonis. All rights reserved
Depends on 1
Used by 0
- No other module depends on it.
Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 1 module in total.
UGTKengine within an engine


