STextBlock::SetTextStyle() does not work
Problem
In Unreal Engine 5.4,
After contruction of STextBlock
widget, if we call STextBlock::SetTextStyle()
, it does not work.
On the other hand, if SimpleTextMode
of STextBlock
is set to true, STextBlock::SetTextStyle()
works.
When I set a breakpoint in the engine source code at the location below, the breakpoint was never triggered except when a new widget was created. If I call SetTextStyle()
on the created STextBlock
, I think it should go through there, but it doesn’t. Since it works fine when SimpleTextMode
is set to true , I’m guessing this is something unfinished work or a bug.
I had to change FSlateBrush UnderlineBrush
of FTextBlockStyle
at runtime, so I tried to use STextBlock::SetTextStyle()
, but it did not work, so I started debugging the engine source. This was quite embarrassed to me because setting SimpleTextMode
to true disables UnderlineBrush
.
Project to reproduce
I created a simple project to reproduce. GitHub Link
After running the editor with the project, if you place the mouse cursor in the hover state for the two leftmost cells and then leave the hover state repeatedly to enter the OnMouseEnter and OnMouseLeave states, the behavior is as the below.
- Cell written NotSimple in the upper left corner
- OnMouseEnter: The text changes to MouseEnter, but the style does not change.
- OnMouseLeave: The text changes to MouseLeave, but the style does not change.
- The cell that says Simple at the bottom left
- OnMouseEnter: The text changes to MouseEnter, and the style changes to the style of “[C] Example Simple Dotted Underline Blue”.
- OnMouseLeave: The text changes to MouseLeave, and the style changes to the style of “[D] Example Simple NotDotted Underline Red”.
The expected behavior is as follows.
- Cell written NotSimple in the upper left corner
- OnMouseEnter: The text changes to MouseEnter, and the style changes to the style of “[A] Example NotSimple Dotted Underline Blue”.
- OnMouseLeave: The text changes to MouseLeave, and the style changes to the style of “[B] Example NotSimple NotDotted Underline Blue”.
- The cell that says Simple at the bottom left
- Same as the current status
A warning to myself
Do not attempt to debug this again or create a pull request.
I think it will be more efficient if Epic handles it from here.
Considering past cases, I think it is much more likely that even if you create a pull request, it will not be accepted.
It may have been because I was not in a good condition, but the emotional fatigue was very strong when debugging.
Else
I posted this to forum. https://forums.unrealengine.com/t/stextblock-settextstyle-does-not-work/1845139