Output data every frame (C#)

In the course of programming my current game, I’ve found it necessary to output certain variables every frame in order to watch them. However, using print() (or Debug.Log() or any other similar statement) outputs data to Unity’s log file, which as we all know has a lot of other things in it. I would like to just have the data I want in an output file. I’ve looked into the C# StreamWriter class, but through my use of it I’ve found that it seems to only exist between curly braces. I’ve googled this problem quite a few times and have come up empty, so I was wondering how/if any of you outputted data to your own file every frame. Any suggestions are appreciated here.

CTRL+Shift+ c will open a console window :slight_smile:

//Normal using statements here
using System.IO;

public class YourClass : MonoBehaviour
{
StreamWriter sw = new StreamWriter(new Filestream("your directory here!", FileMode.Create));

void Update()
{
//Do stuff
sw.Write("Your Data");
}

void OnApplicationExit()
{
//Remember to close your StreamWriter!
sr.Close();
}
}

This should work fine… Please not that I wrote this off the cuff, it may contain errors. :slight_smile:

That works incredibly well. Thank you very much.