# SaveToFile(string)

> Save GraphicsStateCollection to disk.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.Rendering](/engine/6000.7/script-reference/unityengine/rendering.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public bool SaveToFile(string filePath)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Output location of GraphicsStateCollection serialized data.

### Returns

| Type                                                          | Description                                             |
| ------------------------------------------------------------- | ------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if collection successfully saved, false otherwise. |

### Remarks

The file extension of GraphicsStateCollection is \*.graphicsstate. The GraphicsStateCollection is serialized as a JSON object and can be loaded by using [GraphicsStateCollection.LoadFromFile](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/loadfromfile.md) or [GraphicsStateCollection.LoadFromJson](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/loadfromjson.md).

For the Web platform, this function starts a browser download of the file, and uses your `filepath` to name the file. Unity saves this file to the download location you set in the browser preferences. You need to manually move this file to your project Assets folder to use it in Unity.

```csharp
using UnityEngine;
using UnityEngine.Rendering;

public class SaveToFileExample : MonoBehaviour
{
    public GraphicsStateCollection graphicsStateCollection;
    public string filePath;

    void Start()
    {
        graphicsStateCollection = new GraphicsStateCollection();
        graphicsStateCollection.BeginTrace();
    }

    void OnDestroy()
    {
        graphicsStateCollection.EndTrace();
        graphicsStateCollection.SaveToFile(filePath);
    }
}
```

Additional Resources: [GraphicsStateCollection.LoadFromFile](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/loadfromfile.md), [GraphicsStateCollection.SendToEditor](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/sendtoeditor.md).
