Hi, I’m trying to build something like a dialogue system and I need to show a different amount of buttons in different dialogues. So I’ve created a dialogue Widget with a button inside and with the textblock inside button, then a want to duplicate this button and set text for each answer. Here is the code:
for(const auto& button : _buttons)
{
UButton* newButton = NewObject<UButton>(m_buttonTemplate);
newButton = DuplicateObject(m_buttonTemplate, newButton);
m_buttonsContainer->AddChildToVerticalBox(newButton);
if(UTextBlock* text = Cast<UTextBlock>(newButton->GetChildAt(0)))
text->SetText(FText::FromString(button.answerText));
}
But the problem is that UTextBlock points to the same object ( like DuplicateObject function make a shallow copy not a deep) so all the buttons in the end has the same text.
Is there any way to do what I want?
Thanks!