[4.6.0]Change UMG text font size in-game

Hi,

I need to change the font size of a text in my UMG UI dynamically, currectly i tried this: Imgur, it gets called but nothing actually happens :frowning:

The code in the image is inside an Actor Blueprint that has a Widget component attached to it. “Keypad Ref” is a reference to that Widget.

I guess that set node only works in the UI blueprint?

I think i’d rather make a feature request / bug report so everyone can do it the right way :frowning:

An alternative solution could just be to have another text box on top of your current one, with its font already set to the size you want, and you just hide the smaller text and show the bigger text (Set Visibility) once your player has entered the password.

I tried moving my code to the Widget’s blueprint where the function should work, but I hit a bug that makes the engine crash :c Bug Link

Got the same trouble and a workaround recently…

Which “kind” of widget is KeypadRef?

"IF" the text you’ll change the font for is a TextBlock you’ll need to create a new CustomTextBlock class (on C++) in such way you could access/change the Font variable after the widget get constructed, because until 4.6 it’s not exposed on post default editing situations.

If you get interested, go to “Add Code To Project”, pick the “UTextBlock” as base class and give a name as “TextBlockPlus”, when the engine offer to you the option to edit the class, accept.

on the .h file make something as this:

#pragma once

#include "Components/TextBlock.h"
#include "Runtime/SlateCore/Public/Fonts/SlateFontInfo.h"
#include "TextBlockPlus.generated.h"

/**
 * 
 */
UCLASS(BlueprintType)
class UTextBlockPlus : public UTextBlock
{
	GENERATED_BODY()
public:
	UTextBlockPlus(const FObjectInitializer&);
	

	UFUNCTION(BlueprintCallable, Category = "Customization")
	void SetANewFont(FSlateFontInfo NewFontInfo);	
};

after, make the .cpp as this:

#include "TextBlockPlus.h"

UTextBlockPlus::UTextBlockPlus(const class FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{

}

void UTextBlockPlus::SetANewFont(FSlateFontInfo NewFontInfo)
{
	Font = NewFontInfo;
	SynchronizeProperties();
}

Compile, go back to the editor…

If you replace your Standard TextBlocks on your widgets by your new TextBlockPlus they’ll have now a new Function that will allow you to change font and size at your will.

Hope this helps.

The way I went about this is using “Set Render Scale”. A pretty simple function call. I would suggest it so you can get a smooth scale and no snapping to the next size.

34479-resize+font.png

I’m in 4.7.3 at the moment, and this doesn’t seem to be possible. Have you figured out a solution for setting font point sizes dynamically (without using C++)?

I’m pretty sure that this is an issue with structs. Structs in blueprints are very buggy. In 4.8 structs are fixed. Before 4.8 the only way I’ve found to work when you try to change something in it is call ‘Make Struct’ to create a new one with all of the info it needs, and then set your data to that struct. However you can’t call SetFont on the text block in blueprints. I’m not sure about C++ code however.

Thanks MuzzyA this is a good workaround for now, though it would be good if we could change the size of text properly (to avoid blurring from being scaled). Doesn’t seem like it’s an animatable property (I’d like to “pulse” the player’s score whenever points get added or deducted - a fairly common thing to do).