Based in North Yorkshire, England, this is a blog by Craig Gilchrist. His posts explore software development, running a digital agency, family and life.

Using FontAwesome in Unity

Using FontAwesome in Unity

Sometimes we just want the full range of FontAwesome fonts to use in our Unity app and so here’s a quick tutorial of how to do it using TextMesh Pro.

Setup

Add TextMeshPro to your packages

First we need to add the font to our project and set up the package. If you’ve not already got TextMesh Pro then fire up the package manager and add it. It’s usually in the default packages and installed with Unity so you don’t need to download it.

Add the font files

Once we’ve installed TextMesh Pro we need the actual font file that you’re going to use from FontAwesome. You can only do this if you have the Pro license by downloading the desktop files from the fontawesome website.

Once you’ve done this, drag the OTF file that you want to use into your application and accept the default settings. I’m using the Regular-400 font for my app.

Add FontAwesome font to Unity
Add FA Part 2.jpg

Using the Font Asset Creator

Next we need to use the font asset creator to create a TMP Font Asset which is basically a huge sprite sheet that TextMesh Pro uses. To do this we first need to open the Font Asset Creator window by going to Window->TextMeshPro->Font Asset Creator as seen below:

Font Asset Creator.jpg

Once there we’ll see the Font Asset Creator window as follows:

Font Asset Creator Dialog.jpg

First select the font in the Source Font File selection box that we imported earlier.

Next we need to find all of the hex codes for the fonts we need and enter them as a comma separated list into the Character Sequence (Hex) box in the dialog. It’s always more optimal to pick the characters that you want to include in your font file from the FontAwesome website as this will result in a smaller TMP Font asset.

To find the fonts you want, use the standard search functionality in the Font Awesome website and make sure you’ve got the cheat sheet button turned on as shown in the image below:

FontAwesome hex codes.jpg

If the cheat sheet is turned on then the hex code appears below the search result.

If you’re only importing a limited number of fonts then you can leave the default settings in the Font Asset Creator window as follows:

If you don’t change the Character Set to Hex then it won’t work
— A friendly warning
  • Sampling Point Size: Auto Sizing

  • Padding: 5

  • Packing Method: Fast

  • Atlas Resolution: 512 x 512

We do however need to change the character set to: Unicode Range (Hex).

Once you’ve got all the codes in that you want, hit the Generate Font Atlas button and the font will generate.

Once the font has generated hit Save and save the resulting file in your application.

Import the entire set

If you want to import the entire Font Awesome Pro set then here’s a handy cheat sheet for the whole sequence for you to copy and paste into the Character Sequence (Hex) box:

f640,f6ae,f641,f2b9,f2bb,f042,f8f4,f5d0,f34e,f843,f844,f845,f89f,f8a0,f6b0,f8f5,f8f6,f037,f039,f036,f038,f846,f461,f0f9,f2a3,f8a1,f643,f13d,f779,f103,f100,f101,f102,f107,f104,f105,f106,f556,f644,f5d1,f6b1,f187,f557,f358,f359,f35a,f35b,f354,f346,f347,f348,f349,f355,f356,f350,f351,f352,f353,f34a,f34b,f34c,f34d,f357,f0ab,f0a8,f0a9,f0aa,f063,f342,f343,f344,f345,f060,f061,f339,f33a,f33b,f33c,f33d,f33e,f340,f341,f062,f047,f0b2,f337,f338,f07e,f07d,f2a2,f069,f1fa,f558,f5d2,f5d3,f29e,f559,f6b2,f6b3,f77c,f77d,f5d4,f55a,f04a,f7e5,e059,e05a,f335,f336,f645,f646,f8a2,f6b4,f847,f666,f24e,f515,f516,f77e,f732,f733,f05e,f462,f8a3,f02a,f463,f464,f465,f0c9,f432,f433,f434,f435,f6b5,f2cd,f376,f244,f240,f242,f243,f377,f241,f236,f8f7,f8f8,f8f9,f0fc,f0f3,f848,f8fa,f849,f5d5,f5d6,f1f6,f77f,f8a4,f55b,f647,f206,f84a,f84b,f1e5,f780,f1fd,f498,f517,f6b6,f29d,f8fb,f8fc,f8fd,f781,f032,f0e7,f1e2,f5d7,f5d8,f55c,f02d,f5d9,f6b7,f499,f7e6,f518,f5da,f6b8,f7e7,f02e,f5db,f7e8,f8a5,f782,f734,f84c,f84d,f89c,f89d,f84e,f84f,f850,f851,f852,f853,f854,f855,f6b9,f436,f437,f466,f49a,f735,f467,f49b,f49c,f49d,f49e,e05b,f49f,f4a0,f468,f4a1,f438,f7e9,f7ea,f2a1,f5dc,f7eb,f7ec,f0b1,f469,f856,f857,f519,f51a,f37e,f55d,f188,f1ad,f0a1,f140,f648,f649,f858,f46a,f7ed,f207,f55e,f5dd,f64a,f64b,f8a7,f1ec,f64c,f133,f073,f274,f783,f333,f334,f272,f271,f736,f273,f784,f8a8,f030,f332,f8fe,f8a9,f8aa,f083,f6ba,f6bb,f6bc,f786,f6bd,f55f,f46b,f1b9,f5de,f5df,f859,f5e0,f85a,f5e1,f5e2,f5e3,f5e4,f5e5,f5e6,f8ff,e000,f32d,f32e,f330,f331,f0d7,f0d9,f0da,f150,f191,f152,f151,f0d8,f787,f85b,f218,f217,f788,f8ab,f6be,e001,f6bf,f8ac,f0a3,f6c0,f6c1,f51b,f51c,f5e7,f1fe,f080,f201,f64d,f78a,f200,f64e,f7ee,f00c,f058,f560,f14a,f7ef,f7f0,f7f1,f439,f43a,f43b,f43c,f43d,f43e,f43f,f440,f441,f442,f443,f444,f445,f446,f447,f448,f13a,f137,f138,f139,f322,f323,f324,f325,f078,f053,f054,f329,f32a,f32b,f32c,f077,f1ae,f78b,f51d,f111,f1ce,f64f,f8ad,f6c2,f7f2,f328,f46c,f46d,f737,f5e8,f7f3,f017,f24d,f20a,f0c2,f0ed,f381,f738,f739,f73a,f73b,f6c3,f73c,f8ae,f73d,f73e,f73f,f740,f741,f742,f6c4,f743,f0ee,f382,f744,f745,f746,f327,f561,f121,f126,f386,f387,f0f4,e002,f6c5,f6c6,e051,f013,f085,f85c,f51e,f0db,e003,f075,f27a,f4a2,f650,f4a3,f4a4,f4a5,f4a6,f7f4,f4a7,f8af,f4a8,f4a9,f4aa,f4ab,f4ac,f651,f4ad,f4ae,f4af,f4b0,f7f5,f4b1,f8b0,f4b2,f4b3,f4b4,f4b5,f086,f4b6,f652,f653,f51f,f14e,f5e9,f066,f422,f78c,f326,f8b1,f8b2,f562,f85d,f4b7,f46e,f46f,f563,f564,f0c5,f1f9,f6c7,f4b8,f6c8,f8b3,f8b4,f09d,f389,f38a,f449,f7f6,f125,f565,f654,f05b,f520,f521,f7f7,f7f8,f1b2,f1b3,f44a,f0c4,f6cb,f1c0,f2a4,f7f9,f78e,f78f,f747,f108,f390,f748,f655,f470,f219,f522,f6cd,f6ce,f6cf,f6d0,f6d1,f6d2,f523,f524,f525,f526,f527,f528,f85e,f566,f5ea,f5eb,f8b5,f7fa,f529,f567,f471,f5ec,f6d3,f6d4,f155,f472,f473,f474,f475,f476,f4b9,f52a,f52b,f192,f4ba,f019,f568,f6d5,f5ed,f5ee,f5ef,f792,f85f,f860,f569,f56a,f6d6,f6d7,f861,f862,f6d8,f44b,f793,f794,f6d9,f5f0,f795,f749,f74a,f044,f7fb,f7fc,f052,f6da,f141,f39b,f142,f39c,f656,f5f2,f0e0,f2b6,f657,f658,f199,f52c,f12d,f796,f153,f0ec,f362,f12a,f06a,f321,f071,f065,f424,f31d,f31e,f320,f08e,f35d,f14c,f360,f06e,f1fb,f6db,f070,f863,e004,f864,f049,f050,e005,e006,f1ac,f52d,f56b,f182,f44c,f0fb,f15b,f15c,f1c6,f1c7,f5f3,f659,f65a,f316,f1c9,f56c,f6dd,f56d,f31c,f1c3,f31a,f56e,f1c5,f56f,f570,f571,f477,f478,f318,f8b6,f1c1,f319,f1c4,f572,f865,f573,f65b,f317,f574,f65c,f1c8,f1c2,f7fd,f575,f576,f008,f3a0,f8b7,f0b0,f577,f06d,f7e4,f134,f74b,f79a,f479,f578,f7fe,f6de,f024,f74c,f11e,f74d,f6df,f8b8,f0c3,f6e0,f6e1,f7ff,f800,f801,f579,f8b9,f8ba,f74e,f07b,e053,f65d,f07c,f65e,f65f,f802,e054,f660,f031,f866,f44e,f44f,f47a,f04e,f4bb,f803,f52e,f79b,f119,f57a,f661,f662,f1e3,e008,f867,f868,f8bb,f11b,f8bc,e009,e00a,e00b,f52f,f5f4,f0e3,f3a5,f22d,f6e2,f06b,f663,f79c,f79d,f804,f79e,f79f,f869,f000,f57b,f7a0,f7a1,f530,f5f5,f0ac,f57c,f57d,f57e,f7a2,f7a3,f5f6,f450,f451,f664,f19d,f8bd,f531,f532,f57f,f580,f581,f582,f583,f584,f585,f586,f587,f588,f589,f58a,f58b,f58c,f58d,f7a4,f7a5,f58e,f7a6,f8be,f8bf,f0fd,f313,f314,f315,f86a,f805,f6e3,f6e4,f665,f4bc,f4bd,f47b,f4be,f6e5,e05c,f4bf,f4c0,f4c1,f258,f806,f256,f25b,f0a7,f0a5,f0a4,f0a6,f25a,f47c,f255,f257,e05d,f259,f4c2,f4c3,f4c4,f4c5,e05e,f2b5,f4c6,e05f,e060,f6e6,f807,f292,f86b,f8c0,f8c1,f7a7,f7a8,f6e7,f6e8,f0a0,f6e9,f808,e061,e062,f8c2,e063,f809,e064,f6ea,f1dc,f025,f58f,f590,f004,f7a9,f4c7,f5f8,f4c8,f21e,e00c,f533,f6eb,f312,f591,f6ec,f6ed,f1da,f6ee,f453,f454,f7aa,f015,f80a,f4c9,f80b,f80c,f6ef,f86c,f6f0,f7ab,f8c3,f0f8,f47d,f47e,f80d,f80e,f593,f80f,f594,f254,f253,f252,f251,e00d,f6f1,e00e,f74f,e00f,e010,e011,e012,e065,f6f2,f750,f751,f246,f810,f7ac,f7ad,f86d,f86e,f2c1,f2c2,f47f,f7ae,f03e,f8c4,f302,f01c,f310,f311,f03c,f275,f3b3,f534,f129,f05a,f30f,f5f9,f667,f668,f480,f811,f033,f30e,f669,f595,f66a,f8c5,f8c6,f66b,f8c7,f86f,f084,f6f3,f11c,f66c,f66d,f5fb,f596,f597,f598,f6f4,f535,f6f5,f66e,f4ca,e014,e015,f66f,f752,f1ab,f109,f5fc,e066,f812,f8c8,f599,f59a,f59b,f59c,f5fd,f5fe,f5ff,f06c,f4cb,f6f6,f6f7,f094,f536,f537,f149,f3be,f148,f3bf,f1cd,e016,e017,e018,e019,f0eb,f670,f671,f672,f673,f7b2,f870,f871,f0c1,f600,f195,f03a,f022,f8c9,f0cb,f0ca,f601,f124,f602,f603,f023,f30d,f3c1,f3c2,f309,f30a,f30b,f30c,f175,f177,f178,f176,f4cc,f2a8,f455,f59d,f604,e067,f6f8,f0d0,f076,f674,f813,f183,f6f9,f279,f59f,f5a0,f041,f3c5,f605,f606,f607,f608,f609,f60a,f60b,f60c,f60d,f60e,f276,f277,f5a1,f222,f227,f229,f22b,f22a,f6fa,f814,f5a2,f0fa,f675,f11a,f5a4,f5a5,f538,f676,f223,f753,f2db,f130,f3c9,f539,f131,f8cb,f610,e01b,f677,f068,f056,f307,f308,f146,f7b4,f7b5,f10b,f3cd,f3ce,f3cf,f0d6,f3d1,f53a,f53b,f53c,f53d,f872,f873,f611,f6fb,f5a6,f186,f754,f755,f5a7,f678,f21c,f6fc,f6fd,f8cc,f8cd,f245,f8ce,f874,f7b6,f7b7,f875,f001,f8cf,f8d0,f8d1,f6fe,f6ff,f22c,f1ea,f53e,f481,f247,f248,f306,f613,f614,f679,f67a,f7b8,f700,f03b,e01c,e01d,f876,f877,f815,f1fc,f5a9,f5aa,f53f,f482,f483,f1d8,f0c6,f4cd,f1dd,f878,f540,f615,f616,f617,f5ab,f67b,f0ea,f04c,f28b,f1b0,f701,f702,f67c,f703,f304,f305,f5ac,f5ad,f14b,f040,f303,f618,f5ae,f456,e068,f4ce,f816,f295,f541,f756,f4cf,f4d0,f4d1,f757,f095,f879,f87a,f67d,f4d2,f8d3,f3dd,f098,f87b,f2a0,f87c,f67e,f8d4,f8d5,f705,f706,f4d3,f484,f817,f818,f67f,f072,f3de,f5af,f5b0,e069,e01f,e020,f04b,f144,f1e6,f067,f055,f300,f301,f0fe,f2ce,f680,f758,e021,f681,f682,f759,f2fe,f75a,f619,f819,e022,e023,f3e0,f154,f011,f683,f684,f5b1,f485,f486,f685,f02f,f81a,f686,f487,f542,f8d6,e06a,e06b,f707,f12e,f029,f128,f059,f2fd,f458,f10d,f10e,f687,f708,f709,f45a,e024,f7b9,f7ba,f8d7,f8d8,f75b,f75c,f70a,f4d4,f074,e025,f543,f8d9,f2fa,f2fb,f2fc,f1b8,f01e,f2f9,e026,f25d,f87d,f363,f365,f366,f364,f3e5,f122,f75e,f7bd,f079,f361,f4d6,f70b,f81b,f018,f544,f135,e027,f4d7,f61a,f61b,f8da,f09e,f143,f158,f545,f546,f547,f61c,f548,f70c,f156,f7be,f81c,f81d,f5b3,f5b4,f81e,f81f,f7bf,f7c0,f820,f0c7,f8db,f8dc,f61d,f61e,f488,f8f3,f489,f48a,f70d,f7c1,f549,f54a,f70e,f70f,f2f8,f710,f7c2,f002,f688,f689,f010,f00e,f4d8,f87e,f87f,e028,e029,e02a,e02b,e02c,f233,f61f,f064,f367,f1e0,f1e1,f14d,f711,f20b,f132,f3ed,f2f7,f712,e06c,f21a,f48b,f48c,f821,f54b,f290,f291,f07a,f713,f7c3,f2cc,f68a,f5b6,f45b,f822,f68b,f4d9,f090,f2f6,f2a7,f08b,f2f5,f012,f68c,f68d,f68e,f68f,f690,f691,f692,f693,f694,f695,f8dd,f5b7,f7c4,e06d,e02d,e02e,f0e8,f7c5,f620,f7c7,f7c8,f7c9,f7ca,f54c,f8de,f714,f715,f7cb,f7cc,f1de,f3f0,f3f1,f3f2,f118,f5b8,f5b9,f4da,f75f,f760,f48d,f54d,f7cd,f716,f880,f761,f7ce,f2dc,f7cf,f7d0,f7d1,f7d2,e06e,f696,f5ba,e02f,f0dc,f15d,f881,f15e,f882,f883,f160,f884,f161,f885,e030,e031,e032,f0dd,f162,f886,f163,f887,f888,f889,f88a,f88b,f88c,f88d,f88e,f88f,f0de,f823,f5bb,f197,e033,e034,f2f4,f890,f8df,f8e0,f891,f717,f718,f719,f110,f3f4,f5bc,f5bd,e035,f0c8,f45c,f697,f698,f71a,f71b,f5bf,f005,f699,f7d4,f2f3,f089,f5c0,f69a,f621,e036,e037,e038,f762,e039,e03a,f824,f622,f048,f051,f0f1,f249,f7d5,f623,f04d,f28d,f2f2,e06f,f54e,f54f,e070,e071,f550,f21d,f825,f0cc,f551,f12c,f239,f0f2,f5c1,f185,f763,f764,f765,f892,f766,f767,f12b,f5c2,f5c3,f5c4,f5c5,f71c,e03b,e03c,f71d,e03d,f69b,f021,f2f1,f48e,f0ce,f45d,f10a,f3fa,f3fb,f3fc,f48f,f490,f0e4,f3fd,f624,f625,f626,f627,f628,f629,f62a,f62b,f62c,f62d,f826,f02b,f02c,f69c,f827,f4db,f0ae,f828,f1ba,f62e,f62f,e03e,e03f,f768,f769,f76a,f76b,e040,f7d7,f45e,f120,f893,f034,f894,f035,f00a,f009,f00b,f630,f491,f2cb,f2c7,f2c9,f2ca,f2c8,f69e,f165,f164,f08d,f76c,f76d,f76e,f145,f3ff,f69f,f00d,f057,f2ee,f2f0,f2d3,f043,f5c7,f631,f632,f633,f634,f5c8,f204,f205,f7d8,f71e,f71f,e072,f720,f721,f552,f7d9,f5c9,f635,f6a0,f6a1,f76f,f722,f25c,f636,f637,f638,f639,f63a,e041,f238,f7da,f224,f225,e042,e043,e044,e045,e046,f1f8,f2ed,f829,f82a,f895,f896,f723,f1bb,f400,f7db,f7dc,f7dd,f82b,f724,f2ec,f8e2,f091,f2eb,f0d1,f4dc,f4dd,f4de,f63b,f4df,f63c,f7de,f4e0,f8e3,f553,f1e4,f725,f8e4,f726,f26c,f8e5,f8e6,f401,f8e7,e047,e048,f0e9,f5ca,f0cd,f0e2,f2ea,f727,f6a2,f29a,f19c,f127,f09c,f13e,f093,f8e9,f2e8,f2e9,f007,e04a,f406,f4fa,f4fb,f6a3,f4fc,f2bd,f4fd,f4fe,f8ea,f6a4,f4ff,f500,f501,f82c,f82d,f728,f502,f0f0,f82e,f503,f8eb,f504,f82f,f234,e04b,f21b,f505,f506,f507,f508,f235,e058,e04c,f0c0,f63d,f509,f6a5,f830,e073,f2e3,f2e4,f2e5,f2e7,f2e6,e04d,e04e,f6a6,f5cb,f221,f226,f228,e085,e086,f8ec,f492,f493,f03d,f4e1,f4e2,f6a7,f8ed,e074,e075,e076,f897,f770,f45f,f6a8,f027,f6a9,f026,f2e2,f028,f771,f772,f729,f8ee,f831,f8ef,f554,f555,f72a,f72b,f494,f495,f898,f2e1,f8f0,f63e,f773,f774,f775,f899,f83e,f89a,f8f1,f8f2,f832,f833,f496,f5cd,f72c,f72d,f193,f460,f1eb,f6aa,f6ab,f6ac,f72e,f89b,f776,f40e,f40f,f410,e04f,e050,f2d0,f2d1,f2d2,f777,f72f,f4e3,f5ce,f159,f7e2,f0ad,f497,f157,f6ad

If you do this you’ll need to change the Atlas Resolution to 4096x4096 and the packing method to Optimum as it’ll produce a large sprite atlas and will take a while.

Using the fonts

Now the fun part, using the fonts. Using them is as simple as finding them. Find the hex code for the font that you want to use in the FontAwesome website as described earlier.

Next add your button or text to the UI. For this example I’m using a button by choosing Button - TextMeshPro.

Add TMP Button.jpg

Once the control is added, open the TextMeshPro panel in the inspector and add the hex code for your button preceeded by a \u. For example, I’m using the sync-alt icon which has a hex code of f2f1 and so I’ve entered \uf2f1.

TMP FA Inspector.jpg
Sync button.jpg

Make sure the font asset we created earlier in the Font Asset Creator window is selected in the Font Asset dialog and your icon should appear.

That’s it folks. A quick way to use Font Awesome in your apps.

Creating a Twitter Follower Counter with Pimoroni Scroll Bot & Raspberry Pi Zero

Creating a Twitter Follower Counter with Pimoroni Scroll Bot & Raspberry Pi Zero