Thanks! Also remember the class has to be Blueprintable:
The .h file:
UCLASS(BlueprintType, Blueprintable)
class UMyObject : public UObject {
GENERATED_BODY()
public:
UWorld* GetWorld() const;
};
The .cpp file:
UWorld* UMyObject::GetWorld() const {
UObject *outer = GetOuter();
if (outer && outer->IsA() && !outer->HasAnyFlags(RF_ClassDefaultObject)) {
return outer->GetWorld();
}
return nullptr;
}