x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

GameplayDebugger font size

FGameplayDebuggerCategory.DrawData() uses FGameplayDebuggerCanvasContext to draw debug data to the screen. It has pointer to UFont. How can I change the font size?

My implementation:

 void FMyGameplayDebuggerCategory::DrawData(APlayerController* OwnerPC, FGameplayDebuggerCanvasContext& CanvasContext)
 {
     // enabling shadow works
     CanvasContext.FontRenderInfo.bEnableShadow = true;
     
     // scaling factor makes no difference
     CanvasContext.Font->SetFontScalingFactor(3);
 
     // check font size
     float width; // is always 8 (at any scaling factor)
     float height; // is always 15 (at any scaling factor)
     CanvasContext.Font->GetCharSize(*"A", width, height);
 
     for (const FString& debugInfoString : DebugData.DebugStrings)
     {
         CanvasContext.Printf(*debugInfoString);
     }
 }







Product Version: UE 4.15
Tags:
more ▼

asked May 30 '17 at 02:38 PM in C++ Programming

avatar image

bartlomiejwolk
6 4 5

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

GameplayDebugger category uses FGameplayDebuggerCanvasContext for drawing onto the screen. This class has a pointer to UFont used for the text and it's initialized by the UGameplayLocalController when the context is created. Font used by the initialization is GEngine->GetSmallFont(). It's hardcoded and AFAIK there's no API to change it at runtime. I can see three ways to solve this.

First would be to edit the font file used by the small font. Second, is to change the hardcoded value to a larger font. Third way is to create a method inside FGameplayDebuggerCanvasContext to set the font at runtime.

No matter which method you choose, first you need a font file with the size you want. Fonts returned by the GEngine->GetTinyFont, GEngine->GetSmallFont, GEngine->GetMediumFont and GEngine->GetLargeFont are located in Engine Content -> EngineFonts folder.

There isn't really a large font to choose from. Each of the GEngine calls returns normal size font or a smaller one.

You can duplicate the font you want (I recommend Roboto) to any folder inside your Content folder. Open it and change font size. Open Project Settings -> General Settings -> Fonts and set the font. You can also do it by changing the DefaultEngine.ini (in your game repository):

Here I created Fonts/ in the Content folder and put my RobotoLarge font file there.

 [/Script/Engine.Engine]
 LargeFontName=/Game/Fonts/RobotoLarge.RobotoLarge

If you don't want to edit engine code, you can set the small font to the one you created and it should work.


If you want the canvas context to use large font by default, change the font in UGameplayDebuggerLocalController::OnDebugDraw()

Replace:

 FGameplayDebuggerCanvasContext CanvasContext(Canvas, GEngine->GetSmallFont());

with:

 FGameplayDebuggerCanvasContext CanvasContext(Canvas, GEngine->GetLargeFont());

and recompile the engine. UBT should only recompile the GameplayDebugger module.


You can also create an API to change the font at runtime.

Add to the declaration of FGameplayDebuggerCanvasContext class: void SetFont(UFont* font);

and the definition in the cpp file:

 void FGameplayDebuggerCanvasContext::SetFont(UFont* font)
 {
     Font = font;
 }

and recompile the engine.

In your override of the FGameplayDebuggerCategory::DrawData() call CanvasContext.SetFont(GEngine->GetLargeFont());

Recompile the game. When you open GameplayDebugger, the header will still use the default font but your custom debug data should be in large font.

alt text


This applies when overriding Actor's DisplayDebug() method.

You can change font used for displaying text on canvas by getting the pre-set font from UEngine class and setting it in FDisplayDebugManager. See example:

 void MyActor::DisplayDebug(UCanvas * Canvas, const FDebugDisplayInfo & DebugDisplay, float & YL, float & YPos)
 {
     FDisplayDebugManager& displayDebugManager = Canvas->DisplayDebugManager;
     UFont* largeFont = GEngine->GetLargeFont();
     displayDebugManager.SetFont(largeFont);
     displayDebugManager.DrawString(TEXT("Text written with large font"));
 }

Create your own font file and set in the Project Settings as explained above. Restart editor. Run the game, FDisplayDebugManager should now use your custom font.

more ▼

answered Jun 08 '17 at 03:15 PM

avatar image

bartlomiejwolk
6 4 5

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question