Cast UObject * to TMap<...>

Hello,

I have an object of type UObject and I want to cast it to the type TMap. Here is the code:

UObject * Object = BlackboardComp->GetValueAsObject("S_AttackPositions");
TMap<FString, FVector> * AttackPositions = Cast<TMap<FString, FVector> >(Object);

Does someone know how to do the cast correctly? Because this way it doesn’t work. It gives me the following error:

  engine\source\runtime\coreuobject\public\uobject\UObjectBaseUtility.h(330): error C2039: 'StaticClass': is not a member of 'TMap<FString,FVector,FDefaultSetAllocator,TDefaultMapKeyFuncs<KeyType,ValueType,false>>'

Thanks!

I’ve solved it. The compiler wanted the map objects to be pointers and also a reinterpret_cast:

	TMap<FString*, FVector*>& AttackPositions  = reinterpret_cast<TMap<FString*, FVector*>&>(Object);

Take a look at these questions:

note-see-reference-to-class-template-instantiation.

how-to-cast-tarray-to-another-type

Does someone know how to do the inverse cast? From TMap to UObject*?

UObject* Object = reinterpret_cast<UObject*>(&AttackPositions);
BlackboardComp->SetValueAsObject(“S_AttackPositions”, Object);