I have a problem with TMaps. I don’t have the code here but it should be very simple to explain.
I have a member of type TMap inside a class inherited from PlayerState.
When I try to use this variable for adding an element I get a crash (I don’t remember the call stack exactly but I remember it crashed after 2 calls to the Emplace function or immediately after).
The same identical code works perfectly if I declare the TMap as static (I’ve been using it for a couple of weeks without crashes).
I thought it could have been something about the garbage collector, deleting elements inside the TMap (it seemed to be strange as the elements are of type FName and uint32 that shouldn’t be garbage collected but I had no clue about other possibilities).
I tried to use a TArray of struct (the struct just had an FName and a uint32 as for the map) instead than a TMap and when trying to add an element to it I got the same crash! Again if declaring the TArray as static everything worked well. This has been just a test as I have to use a TMap.
So, I don’t think the element inside these two structures are garbage collected, I think are the elements theirselves that are or maybe they don’t keep the memory reserved, or something like that.
Do you have any suggestion about what I could investigate to understand where the problem can be?