GetDesiredSize of Text Widget Return 0

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();