Building custom Font with script, can not change CharacterInfo

I wanted to make several custom bitmap fonts for my game, and after looking into it I realized that this is a painstaking process to set up in Unity. So I decided to write an editor script to automatically generate the rects for my characters. The problem is, whenever I try to set the CharacterInfo struct inside my fonts, the change doesn’t seem to actually happen.
Here’s the relevant code:

if(changed) {
    var nci = new CharacterInfo();
	nci.minX = (int)currentRect.xMin;
	nci.maxX = (int)currentRect.xMax;
	nci.minY = (int)currentRect.yMax;
	nci.maxY = (int)currentRect.yMin;
	nci.index = ci.index;
    currentFont.characterInfo[currentChar] = nci;
    Debug.Log(currentFont.characterInfo[currentChar].minX);
}

After having set the new CharacterInfo struct, the value of the old CharacterInfo is always logged. Is this something new in Unity 5? It seems some things have changed, such as the way the uv and vertex rects are represented, but I don’t see how that should affect the behaviour. Is there something else I’m missing?

My current tentative solution involves using [Shoebox][1] with [this script][2], but I have many other reason to want my own editor script to do the same thing. The linked script uses the old UV and verts rects, which are deprecated and throw warnings, so an up-to-date solution would still be nice! However, I am able to proceed with this, albeit with annoying warning. [1]: http://renderhjs.net/shoebox/ [2]: http://www.benoitfreslon.com/unity-generate-and-import-a-bitmap-font-with-a-free-tool

1 Answer

1

Probably not revelant to @limez anymore, but to anyone else who finds this topic in the future - while I wasn’t able to solve the problem, setting the characterInfo’s array size to 0 in the inspector makes it so you can edit it through script and the changes will stick. Otherwise they reset to a previous logged value like limez said.

I've tried int[][] and int[,] with the above example json, which doesn't seem to work. I've also tried using a seperate class: public IntArray[] test; public class IntArray { public int[] vector2; } This DOES work, however only if the json structure is as: "test": [ { "vector2": [0, 1] }, { "vector2": [2, 3] } ] I'm trying to store vector2 coordinates and though this version does work, the first json example seems a lot cleaner and readable to me, but I don't know how to get that result.