# Loading Blueprint From C++

**URL:** <https://forums.unrealengine.com/t/loading-blueprint-from-c/212630>\
**Category:** C++\
**Tags:** unreal-engine, UE4-26\
**Created:** [April 11, 2021, 5:52am UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630 "2021-04-11T05:52:24Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [April 11, 2021, 2:49pm UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/3 "2021-04-11T14:49:36Z")

</div>

Build.CS:

```cpp
PublicDependencyModuleNames.AddRange(
	new string[] {
		"Core",
		"Json",
		"Engine",
		"CoreUObject",

		"AssetRegistry"
	}
);

```

* * *

Somewhere.H

```cpp
#include "AssetRegistryModule.h"

```

Somewhere.CPP

```cpp
void MyBase::LoadStuff()
{
	TArray<FAssetData>AssetData;

	const FAssetRegistryModule & AssetRegistry =
	FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");

	AssetRegistry.Get().GetAssetsByClass( TEXT("MyBaseClass_NAME") , AssetData );

	// check if valid:
	for (const auto & Data : AssetData)
	{
		if (Data.AssetName.ToString().Equals( TEXT("MySubClassIneed") , ESearchCase::CaseSensitive) )
		{
			UBlueprint* BP = GetBlueprintFromCDO(Data.GetAsset());
			if (BP && BP->GeneratedClass.Get())
			{
				if(
					!BP->GeneratedClass.Get()->HasAnyClassFlags(CLASS_Deprecated|CLASS_Hidden)
				) {
					// UMyBaseType* CDO = GetCDOfromBlueprint<UMyBaseType>(BP);
					// I do stuff in CDO.. 'GetCDOxx' above doesn't exist in your copy of Unreal.
				}
				break;
			}
		}
	}
}

```

* * *

* * *

Now, _what I actually do_, but it’s optional… I create a custom UBlueprint class and a custom asset factory to create blueprints from this class:

```cpp
UCLASS(BlueprintType)
class MYPROJECT_API UMyCoreSystemBlueprint : public UBlueprint
{
	GENERATED_UCLASS_BODY()

#if WITH_EDITOR

	virtual bool SupportedByDefaultBlueprintFactory() const override
	{
		return false;
	}

#endif
};

```

I will not get into details of how to create asset factory, [I talk about asset factory here](https://forums.unrealengine.com/t/is-it-possible-to-add-custom-asset-category-for-custom-data-asset/105162/2).

* * *

So, back to topic, with a custom BP class I make sure I load Blueprints I need without hardcoding name of classes into C++ files (hardcoded text and names is a bad practice):

```cpp
AssetRegistry.Get().GetAssetsByClass
(
	UMyCoreSystemBlueprint::StaticClass()->GetFName() , AssetData, true
);

```

---

_[View the full topic](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630)._
