> For the complete documentation index, see [llms.txt](https://pahutyakv.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pahutyakv.gitbook.io/docs/savely/binary.md).

# Binary

**Savely.Binary** provides simple binary-based data persistence. It is ideal for fast serialization of arbitrary serializable objects, including complex structs and classes, where human readability is not required.

***

### <mark style="color:$success;">**Saving Data**</mark>

Serializes any `[Serializable]` or `[SerializeField]` type into a binary file.

```csharp
Savely.Binary.Save("player_profile", profileData);
```

If `data` is `null`, an exception is thrown.

***

### <mark style="color:$success;">**Loading Data**</mark>

```csharp
PlayerData profile = Savely.Binary.Load("player_profile", defaultValue);
```

* Returns `defaultValue` if the file does not exist.
* Returns `defaultValue` if deserialization fails.
* Logs a warning on load error.

***

### <mark style="color:$success;">**Check if File Exists**</mark>

This checks within the active Savely root directory.

```csharp
bool exists = Savely.Binary.Exists("player_profile");
```

***

### <mark style="color:$success;">**Deleting a File**</mark>

If the file does not exist, nothing happens.

```csharp
Savely.Binary.Delete("player_profile");
```

***

### <mark style="color:$success;">**Changing the File Extension**</mark>

You can customize the extension if needed (e.g., `.save`, `.dat`, `.bin`).

```csharp
Savely.Binary.SetExtension("save");
```

***

### <mark style="color:$warning;">**Requirements & Limitations**</mark>

Supported:

* Polymorphic types (via standard `BinaryFormatter` serialization)
* `[Serializable]` classes and structs
* Primitive types (`int`, `float`, `bool`, etc.)
* Fields with `[SerializeField]`
* Nested objects (complex hierarchies)
* Enums

Limitations:

* Unity-specific objects that are **not** `[Serializable]` (e.g., `GameObject`, `MonoBehaviour`, `ScriptableObject`)
* Cross-platform or cross-version serialization can fail if types change
* Not human-readable
