Skip to main content

Hi Figma devs 😃


I’m trying to load all fonts before updating layer character.


const fontArray = =
{ family: 'Roboto', style: 'Regular' },
{ family: 'Roboto', style: 'Bold' },
{ family: 'Font Awesome 5 Pro', style: 'Solid' },
{ family: 'Font Awesome 5 Pro', style: 'Light' },
];

fontArray.map(async (font) => {
await figma.loadFontAsync(font);
});

Unfortunately, I get a memory error. Can somebody help, please?

Thanks in advance


You can’t use async in a map so this works synchronously and likely the fonts aren’t loaded before you try to change the characters. Also all these four calls would happen at the same time, a memory error may be caused by trying to load multiple fonts at the same time.


Why not load all fonts without manually specifying them?


selection.forEach(async (font) => {
await figma.loadFontAsync(font.fontName as FontName);
});

I got it working already 😀 Thank you for the quick responses.


I’m doing it like this:


await figma.loadFontAsync(node.fontName as FontName);
node.characters = value;

Smashing! This took me an age to figure out myself haha.


Hi!


I got the fonts working like this:


// Function for loading all the needed fonts
const loadFonts = async () => {

await figma.loadFontAsync({ family: "Work Sans", style: "Regular" })
await figma.loadFontAsync({ family: "Work Sans", style: "Medium" })
await figma.loadFontAsync({ family: "Work Sans", style: "Bold" })

console.log("Awaiting the fonts.")

}

// Load the fonts by running the function
loadFonts().then(() => {

// Make them useful
doSomethingElseWithThem()
console.log("Fonts fetched and ready to go!")

})

Maybe this helps someone!


Reply