How to prevent a Tmultimap from being garbage-collected if it cannot be declared with UPROPERTY?

Tmultimap is not allowed to be declared with UPROPERTY.

If what you mean is preventing UObjects inside the multimap from being garbage collected, store TSharedObjectPtr instead of UTheObjectClass* inside the multimap.

Im not storing UObjects, but int32 values with FString keys. The game does not freeze during the first gameplay, but once I run the game second time it crashes as soon as the functions referring to TMultiMap are called.

Hmmm… Then it has nothing to do with garbage collection: only UClasses are garbage collected (neither of int32, FString nor TMultiMap is garbage collected).
Can you give more details of what is happening? (code declaration of the map and where it is, code that crashes, crash output or log…)

Thanks for trying to help me. Here is the code. As I said, if I run the game for the first time, the code works, saves and successfuly retrieves data. Running it for second time though causes the engine to crash as soon as the functions shown in uploaded images are called.

Do you know where the code crashes, or do you have the error output or UE log?

Actually, after compiling it and running as standalone win64 game, it does not crash and works, but from time to time, the game crashes with the error: Array out of bounds. This crash occurs mostly when TMultiMap receives many queries in short time (like 7 or 9) :confused:

Can you post the error output from the log? If it references a file and line number, what code is there?