menu_bookDocumentation
File System: Sandboxed Virtual Filesystems for Data Persistence
Standard .NET System.IO.File access is restricted in s&box. Instead, use the provided BaseFileSystem virtual filesystems that sandbox access to specific game directories.
Available File Systems
| FileSystem | Purpose | Path Example |
|---|---|---|
| FileSystem.Data | Per-game data storage | sbox/data/org/game/ |
| FileSystem.Mounted | Aggregate of all mounted content (core + game + dependencies) | Read-only |
| FileSystem.OrganizationData | Shared data across games in your org | sbox/data/org/ |
Reading and Writing Text
CSHARP
if ( !FileSystem.Data.FileExists( "player.txt" ) )
FileSystem.Data.WriteAllText( "player.txt", "Hello, world!" );
var hello = FileSystem.Data.ReadAllText( "player.txt" );Reading and Writing JSON
Only properties (not fields) are serialized by default:
CSHARP
public class PlayerData
{
public int Level { get; set; } // Serialized ✔️
public int MaxHealth { get; set; } // Serialized ✔️
public string Username; // NOT serialized ❌ (field, not property)
public static void Save( PlayerData data )
{
FileSystem.Data.WriteJson( "player.json", data );
}
public static PlayerData Load()
{
return FileSystem.Data.ReadJson<PlayerData>( "player.json" );
}
}Key Points
- System.IO.File is blocked — always use FileSystem.
- WriteJson/ReadJson only serialize properties, not fields
- FileSystem.Data is per-game, isolated from other games
- FileSystem.Mounted is read-only aggregate of all content
Was this helpful?