.ctor() is too complex - unfixable error!

I have a game I’m converting to C# in Unity, which uses an array I’m defining in C# as an ArrayList due to its mixed data type (strings and doubles). The array is around 30000 elements long, all typed in, containing all the main information about the game, so it has to remain as one array, or at least in one block of data in whatever form is best.

However even putting this array in a separate script file with nothing else, I still get the above error. Most ‘fixes’ I’ve read basically suggest splitting it up, but I can’t see any way of doing this with a single array central to everything that happens in the game.

So what’s causing this error and is there a way to stop it which allows me to keep it as one array? I can’t really understand why this is being flagged up as ‘too complex’ anyway, it seems a completely arbitrary thing to decide - what constitutes ‘too complex?!’ Too many lines? Too many entries per line? Too many elements? Too many zeros? Too many references to farm animals?

Thanks for any help.

Putting huge amounts of data into your code is a bad idea across the board. Load it in from a file instead - you can just have it as plain text with one element per line, or put it in a JSON format or something similar if that works better, and load it in using Newtonsoft’s Json.NET (the included JsonUtility is not the best at collections, and I suspect would have trouble with your data). You could use Unity’s TextAsset class to load the file itself, but I’m not sure how it’d handle such a large file, and it might be better to put the text file in StreamingAssets and use C#'s File class to read it in instead.

I also have a hard time imagining that a single 30000-element list is the best way to store your data. If you could give an example of what kind of information is in there, I may be able to recommend a better approach to that.

Thanks for that - a Json format would certainly suit the data better, I’ll look at how to implement it. I tried splitting the array into its components, but the smallest array is still around 12k entries, and with the other arrays, running still ended up throwing the ‘too complex’ error. Basically I have a video with a few thousand chapter points, which the array indexes with names and timings (a string and int value per entry), so there’s absolutely no way around that. I will look into the Json option though.

There are a number of open standard closed caption file formats such as SRT, and I’m sure many of them have readily available/free C# code for loading/reading/displaying them, such as this one I found for SRT. Why not use something like that?

Thanks but it’s not to do with subtitles, it’s a game constructed of lots of video clips, the data in the array relates to each clip. Json is the solution I think!