Is there a way to get actual blueprint class from the Asset Registry?

When listing classes from the asset registry the ‘Get Class’ function returns ‘Blueprint’ or other basic asset types. I would like to get a class which can then be used to cast for a desired custom blueprint subclass. Is this possible in blueprint scripting?

2 Likes

you ever find a solution to this, running into the same problem?

1 Like

same here :wink:

1 Like

I assume you want to cast to blueprint in C++, no you can not do that as it’s technically impossible as class needs to exist in C++ to be valid C++ type. Everything gets compiled down to pure numbers, classes are practically just logical feature that only exists in compilation process and desolves in to machine code, so you can not use the class from blueprint.

You can only get UClass pointer from UBlueprint class via GeneratedClass variable and then use it to spawn actor for example, but you can only cast it to the most highest class that is in C++ and it’s related to blueprint. I think (and thats just a guess) you could make node in blueprint in C++ by doing some hackish stuff in reflection system or (and this one for sure) by making new UK2Node.

1 Like

Turns out it is quite easy to get the parent class of a blueprint asset. The asset registry will always return UBlueprint objects, but those objects themselves have a property ParentClass, which is the class that you’re probably interested in. This class corresponds with the Native Parent Class that you can see when hovering over an asset in the editor.

alt text

For my purpose, I wanted to distinguish between inherited classes and the actual class itself too, which you can do using the IsChildOf method once you have the class you desire.
In the snippet, Asset is of type FAssetData, and ClassType is a pointer to a UClass.

const UBlueprint* BlueprintAsset = Cast<UBlueprint>(Asset.GetAsset());
if (BlueprintAsset)
{
	const bool IsClass = BlueprintAsset->ParentClass == ClassType;
	const bool IsChildClass = BlueprintAsset->ParentClass->IsChildOf(ClassType->StaticClass());
	if (IsClass || AllowInheritance && IsChildClass)
	{
		//...
	}
}
3 Likes

Unless I misunderstood the question, the correct answer (based on Wallby’s answer) would be:

    UClass* UMyBlueprintFunctionLibrary::GetClassFromBlueprintAsset(const FAssetData& Asset)
    {
    	const UBlueprint* BlueprintAsset = Cast<UBlueprint>(Asset.GetAsset());
    	if (BlueprintAsset)
    	{
    		return BlueprintAsset->GeneratedClass;
    	}
    	return nullptr;
    }
5 Likes