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"

TMap with Key/Value UserWidget pointers lose references on Compile

I have a UserWidget subclass with a TMap UPROPERTY where the key and value are both UUserWidget pointers (ie TMap). After creating a BP instance of my widget, the inspector lets me properly assign to the map without issue, showing the correct available widgets in the Hierarchy. If I save the Widget in the editor, those values persist. However, if I Compile the blueprint, I'll lose the values every time, and all the Map entries will be empty.

Any ideas?

Product Version: UE 4.19
Tags:
more ▼

asked Aug 06 '18 at 05:50 PM in C++ Programming

avatar image

Shinika8
13 1 2 6

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

1 answer: sort voted first

I'm afraid you can not use UUserWidgets as keys, you could try to generate a unique ID as your key and the value could contain a struct holding your pair (or even TPair).

To define your own keys what you normally do is to define how to compare your keys calsses and create a MapKeyFunction that the TMap will use to compare one to another.

The following is an example that you could follow:

 #include "Engine/EngineTypes.h"

 template<typename ValueType>
 struct TMyClassMapKeyFuncs : TDefaultMapKeyFuncs<UMyClass, ValueType, false>
 {
     static FORCEINLINE bool Matches(UMyClass A, UMyClass B)
     {
         return A == B; // Do your own compare here!
     }
 
     static FORCEINLINE uint32 GetKeyHash(UMyClass Key)
     {
         return ::GetTypeHash(Key);
     }
 };
 
 
 TMap<UMyClass, UUserWidget, FDefaultSetAllocator, TMyClassMapKeyFuncs<UUserWidget>> MyTMap;

The code above is written out of my head so it might need some love ^^

Cheers, Moss

more ▼

answered Aug 06 '18 at 10:00 PM

avatar image

Moss
6.4k 127 98 606

(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