Download

Find the UBlueprint which generated a UClass?

Is there a straightforward way to get the UBlueprint which was used to generate a given UBlueprintGeneratedClass? Basically getting a UBlueprint* from a UClass*.

I can probably just loop through asset data until I find the right BP, but that seems silly.

template<typename T>
T* GetCDOfromBP(UBlueprint* Blueprint)
{
	if (Blueprint==nullptr)
	{
		return nullptr;
	}

	const UClass* BlueprintClass = Blueprint->GeneratedClass;

	return Cast<T>(BlueprintClass->ClassDefaultObject);
}
UBlueprint* GetBPfromCDO(UObject* OBJ)
{
	UBlueprint* BP = nullptr;

	if (OBJ != nullptr)
	{
		BP = Cast<UBlueprint>(OBJ);

		if (BP == nullptr)
		{
			BP = Cast<UBlueprint>(OBJ->GetClass()->ClassGeneratedBy);
		}
	}

	return BP;
}
2 Likes

ClassGeneratedBy is what I was looking for. Thanks!