Unity CSV import and export

I recently had a need to exchange data between the Unity game engine and spreadsheet software. The simplest common format supported by most spreadsheet programs is CSV (Comma Separated Values.) I had assumed that this would be such a common thing to do it would be built into either the .NET or Unity libraries. It turned out this is not the case.

I started my quest, as I usually do, by searching for existing solutions. (That is, searching for existing solutions while attempting to steer clear of the weeds using -stackoverflow.) And there were no shortage of solutions to choose from. However, after examining several solutions in detail they were all far too heavy weight for my needs. Most had complicated installation steps and handled many more features than I needed.

What did I need?

My requirements were as follows:

  • a simple short and clear script
  • can handle quoted entries containing commas
  • can handle new lines within entries

While there are many solutions out there that will handle the 2nd and 3rd requirements, there are very few that meet the first. So after wasting several hours searching and examining other options I gave up my search and decided to throw something together myself.

Back when I was a young, impressionable programmer, I would have frowned on this Not Invented Here behaviour. But sometimes a quick solution is better than the best solution.

The result is not big enough to justify a library or repository. It’s nothing more than a few functions useful for dealing with the ins and outs of CSV files. So I put it in a Gist. My hope is that other programmers will find these routines useful. If so, please link to the Gist or this post and hopefully it will bubble up and help some future programmer with uncomplicated requirements.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.