Uses the Asset Registry to determine whether a SoftClass is a child of another class, without loading it. NOTE: This snippet has limited utility, traversing the asset registry may be slower than just loading the class in some cases!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
void UMyAssetManager::SetAssetRegistryTempCachingEnabled(const bool bEnabled)
{
IAssetRegistry::Get()->SetTemporaryCachingMode(bEnabled);
}
bool UMyAssetManager::SoftClassIsChildOf(const TSoftClassPtr<UObject>& SoftClass, const TSubclassOf<UObject>& Class)
{
if (SoftClass.IsNull() || Class == nullptr)
{
// Class is invalid, do nothing
return false;
}
else if (const UClass* LoadedClass = SoftClass.Get())
{
// Class is already loaded, use the fast path
return LoadedClass->IsChildOf(Class);
}
else
{
// Use Asset Registry for Unloaded Classes
// Caution: This may be slow if TempCaching is disabled.
FAssetData AssetData;
if (UAssetManager::Get().GetAssetDataForPath(SoftClass.ToSoftObjectPath(), AssetData))
{
if (AssetData.AssetClass == Class->GetFName())
{
return true;
}
else
{
// Unfortunately the temp class hierarchy data is private, so we can't walk it manually.
TArray<FName> AncestorClasses;
IAssetRegistry::Get()->GetAncestorClassNames(AssetData.AssetClass, AncestorClasses);
return AncestorClasses.Contains(Class->GetFName());
}
}
return false;
}
}