The simple solution is to use MyObject->GetClass()->GetSuperClass(), since UClass values have a GetSuperClass() function which returns their immediate parent class.

Blueprints

If the UObject is a blueprint, a different approach needs to be used. Blueprint classes show up as UBlueprint, which always has the parent BlueprintCore. In this case, you need to use the ParentClass property to get the actual parent:

auto* BP = Cast<UBlueprint>(MyObject);
UClass* ActualParent = BP->ParentClass;

Data Assets

Similarly, with data assets the superclass is UDataAsset. To retrieve the actual parent asset type, you can simply use GetClass

auto* DA = Cast<UDataAsset>(MyObject);
UClass* ActualParent = DA->GetClass();

(Technically speaking this is not the parent class of a data asset, it’s the type of the data asset)