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"

Strange behaviour of UUserWidget::CreateWidgetInstance

If UUserWidget::CreateWidgetInstance called a few times with the same name parameter, it creates a new widget instance only first time, following calls return a pointer to a previously created widget without any errors or warnings.

Test code:
UUserWidget* Widget1 = UUserWidget::CreateWidgetInstance( *this->GetWorld(), UMyUserWidget::StaticClass(), "TestNameOne" );
UUserWidget* Widget2 = UUserWidget::CreateWidgetInstance( *this->GetWorld(), UMyUserWidget::StaticClass(), "TestNameOne" );
UUserWidget* Widget3 = UUserWidget::CreateWidgetInstance( *this->GetWorld(), UMyUserWidget::StaticClass(), "TestNameTwo" );
UE_LOG( LogTemp, Log, TEXT( "%s" ), (Widget1 == Widget2 ? TEXT( "TRUE" ) : TEXT( "FALSE" )) );
UE_LOG( LogTemp, Log, TEXT( "%s" ), (Widget2 == Widget3 ? TEXT( "TRUE" ) : TEXT( "FALSE" )) );
Output is TRUE FALSE.

If this is a Create method, I expect it to create a new instance, not to return a pointer to the existing one.
Is it a bug or it should be like this?

Product Version: UE 4.20
Tags:
more ▼

asked Jul 20 '18 at 10:58 AM in C++ Programming

avatar image

ntaltech
3 1 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I didnt know about this function but you prolly should be 7sing the global CreateWidget《》function

more ▼

answered Jul 20 '18 at 04:04 PM

avatar image

92Rob
98 1 3 8

avatar image ntaltech Jul 20 '18 at 05:31 PM

Thanks for the tip, this function is really solving names problem (also, using NAME_None helps too). Though, CreateWidgetInstance behavior is still pretty strange, as for me.

avatar image 92Rob Jul 20 '18 at 08:23 PM

Well yes because FNames are unique, you cannot create 2 objects with the same fname so the function just returns the one created previously

avatar image ntaltech Jul 21 '18 at 09:46 AM

Oh, I see, thanks for explaining

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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