The better question is why are you doing this often? It sort of goes against the whole need for a map.
Explain why you need this mechanism that will become very intense computationally.
If you want to do a test if a key has been used (and you don’t want to overwrite the set value) then keep an array of used keys in parallel and use that as your guide instead of hammering a map for something it is not intended to be used for.
You could use this combination of functions if you are dead set on this
I wrote a quick test in a static lib and it works as intended
.h
UFUNCTION(BlueprintCallable)
static bool FindByValue(TMap<FString, FString> passedMap, FString NeededValue);
.cpp
bool UMapTool::FindByValue(TMap<FString, FString> passedMap, FString NeededValue) {
TArray<FString> out;
passedMap.GenerateValueArray(out);
return out.Contains(NeededValue);
}
It flatters the maps values to a single array which you can just use contains on. It should be optimized & beats iterating over keys => values to get it.
Though I’d still have to read up how to convert it to take in a generic TMap. (might require a custom k2Node).
Seems templates are a pain in ue from the c++ side. For now do a stiff implementation of the needed TMap. If I find a way to use it with templates I will update my answer. (Seems you can have T templates but it won’t expose it to blueprints)
Here is the equivalent in BP but not sure about the performance.
