This compiles just fine:
TMap< FName, USoundWave > m_SoundWaves;
If I add the following code
MyClass::Set(FName PropertyName, const USoundWave& InSound)
m_SoundWaves.Add( PropertyName , InSound );
I get this error:
E:\ue4-engines\UE_4.17\Engine\Source\Runtime\Core\Public\Containers/Set.h(164): error C2280: 'TTuple<KeyType,ValueType>::TTuple(const TTuple<KeyType,ValueType> &)': attempting to reference a deleted function
Btw, the same code with FSlateSound instead of USoundWave works just fine.
What is wrong here? Is it not possible to use any class I want with TMap?
Is USoundWave missing something?
Hi. UObjects can’t be copied via their constructors. To store UObjects inside arrays or maps you have use either pointers (USoundWave*) or weak references (TWeakObjectPtr). To work right with GC you have to make all pointers to UObjects visible for UE reflection system. It can be achieved by placing TMap into UPROPERTY() when your map is inside an other UObject. If you need to store UObject references insine non-UObject class you can use FGCObject class. Just add this to inheritance list of your class and override
virtual void AddReferencedObjects(FReferenceCollector& Collector) override;
In this function you have to add all UObjects you captured in the class to a Collector object.
If you decided to use TWeakObjectPtr you have no need to deal with GC, but weak references doesn’t prevent UObjects from unloading. When object will be unloaded this reference will became invalid.
Thank you so much!
I am just putting pointers into the TMap for now.
It works just out of the box without any problems.
Thank you for giving me all these options. I “fear” I will - at a later point - have to come back and try to understand and use some of the knowledge you gave me there.