Is it true that text widget in Blueprint, GetDesiredSize() always return zero regardless of any text entered in that widget?
Here’s an unresolved issue as well:
Is it true that text widget in Blueprint, GetDesiredSize() always return zero regardless of any text entered in that widget?
Here’s an unresolved issue as well:
Hello Pelangi,
After doing a bit of digging I was able to find a post with information on this subject. I have provided a link below. I hope that this information helps. As a note, you maybe getting a return of zero because the the widget has not been fully added to the screen when you are calling “Get Desired Size”. There is a chance that calling this on Event Construct will return 0,0 because it is being called before the widget you are testing has been fully added. As a test you can call this on tick to see if you are given any values. As stated above, see the linked thread for more information.
Link: UMG Widget GetDesiredSize() - UI - Epic Developer Community Forums
Make it a great day
This can be remedied by using “Force Layout Prepass” before “get desired size”
thank you
that was helpful
This worked for me in UE4.26 on a rich text block. The rich text block is inside a canvas panel and is set to auto-size and auto word wrap.
Header:
// The rich text block to use for displaying the text.
UPROPERTY(Transient, meta = (BindWidget))
URichTextBlock* DynamicRichTextBlock;
CPP:
DynamicRichTextBlock->ForceLayoutPrepass();
UE_LOG(LogTemp, Warning, TEXT(“DynamicRichTextBlockSize %s”), *DynamicRichTextBlock->GetDesiredSize().ToString());
return DynamicRichTextBlock->GetDesiredSize();
Thank you a lot!