# 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:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [April 11, 2021, 5:52am UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/1 "2021-04-11T05:52:24Z")

</div>

I have a subsystem blueprint whose parent class in c++ is marked as abstract. The blueprint never loads automatically when I open the editor. The blueprint loads after double-clicking it. So how can I load the blueprint automatically without clicking on it? I was trying to just statically load the blueprint but it is not working.

```
FString spawnedBlueprintReference = TEXT("Blueprint'/MortarPlugin/MortarPlugin/Blueprints/BP_MortarResourceManager.BP_MortarResourceManager'");

		UObject* loadedObject = StaticLoadObject(UObject::StaticClass(), nullptr, *spawnedBlueprintReference);
		
		if(loadedObject)
		{ 
            //Getting Here
			UE_LOG(LogTemp, Warning, TEXT("Loading Blueprint subsystem SUCESS"));
		}
		else
		{
			UE_LOG(LogTemp, Warning, TEXT("Loading Blueprint subsystem NO SUCESS"));
		}

```

But this doesn’t load the blueprint. How can I load it ?

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [April 11, 2021, 12:27pm UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/2 "2021-04-11T12:27:10Z")

</div>

Bump any help ☹

---

<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
);

```

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [April 11, 2021, 3:43pm UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/4 "2021-04-11T15:43:42Z")

</div>

> [@BrUnO\_XaVIeR](#):
>
> `GetBlueprintFromCDO`

Thank you for the detailed help and also for the second method It is very good.I am trying approach 1 first. I am unable to find this method GetBlueprintFromCDO is it available in UE4 ? I cannot find it : (

---

<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, 3:45pm UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/5 "2021-04-11T15:45:06Z")

</div>

That is not an Unreal Engine function either. I have created it somewhere in my libs.  
But you don’t need it to make it work, class loading should work without that.

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [April 11, 2021, 4:02pm UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/6 "2021-04-11T16:02:01Z")

</div>

oh ok But I am unable to make it work I must be doing something wrong : ( I have an abstract subsystem class named as UMortarResourceManager and I have blueprint BP\_MortarResourceManager. I am trying to load BP\_MortarResourceManager so I write this code

```
TArray<FAssetData>AssetData;

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

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

```

But the blueprint is still not loading

---

<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, 4:10pm UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/7 "2021-04-11T16:10:32Z")

</div>

> [@FinalRockstar](#):
>
> `AssetRegistry.Get().GetAssetsByClass(TEXT("UMortarResourceManager"), AssetData);`

* * *

> GetAssetsByClass(FName ClassName, TArray& OutAssetData, bool bSearchSubClasses = false);

Add a “true” to the end of function call.  
Oh and you probably shouldn’t add any ‘U’, or ‘F’ prefixes either.

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [April 11, 2021, 4:31pm UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/8 "2021-04-11T16:31:59Z")

</div>

still not able to do : ( I am doing this in Begin Play of the main actor.

```
AssetRegistry.Get().GetAssetsByClass(TEXT("MortarResourceManager"), AssetData,true);
```

---

<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, 4:45pm UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/9 "2021-04-11T16:45:05Z")

</div>

Hmm… I don’t think you should do this stuff mixed with gameplay code.  
There could be a step missing somewhere.

* * *

Anyway, If nothing of that is working for you, try to have a property somewhere, maybe on a GameInstance:

```auto
UPROPERTY(Category="Subsystems", EditAnywhere)
TSubclassOf<UMySubsystem> SystemClass;

```

Then assign your BP class to that property.  
See if that will force your sub class to load by default.

And use that GameInstance as default GameInstance on Project Settings.  
When there is a hard reference, it is always loaded:

 ![UE_Dependency](https://d3kjluh73b9h9o.cloudfront.net/original/3X/f/4/f42727b2824c76b17c64f9d844bd94a361b138c5.png)

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [April 11, 2021, 4:54pm UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/10 "2021-04-11T16:54:12Z")

</div>

This is a c++ plugin which is meant to be used with other games so is it feasible to have that in game instance ? : ( as the game would also be having it’s own game instance. Anyways I will debug more as according to you is should work so I must be doing something wrong. I will get back . Thanks for the quick replies : )

---

<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, 5:16pm UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/11 "2021-04-11T17:16:29Z")

</div>

> [@BrUnO\_XaVIeR](#):
>
> `Data.GetAsset()`

Did you actually use the _GetAsset()_ function ?!  
You need to call that from the asset data.

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [April 11, 2021, 5:20pm UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/12 "2021-04-11T17:20:37Z")

</div>

This AssetData is 0 size so it is not going in loop at all

---

<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, 5:28pm UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/13 "2021-04-11T17:28:30Z")

</div>

I ran this quick test, and the Editor loaded ALL blueprints subclass of UBlueprint::StaticClass():

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

	AssetRegistry.Get().GetAssetsByClass( TEXT("Blueprint") , AssetData, true );

	for (const auto & Data : AssetData)
	{
		LOG::CS_NAME(ESeverity::Warning, Data.GetAsset()->GetFName() );
	}

```

* * *

* * *

> CS: Warning: ActorMacros  
> CS: Warning: AITesting\_MoveGoal  
> CS: Warning: DefaultBurnInOptions  
> CS: Warning: ContentBrowserOverview  
> CS: Warning: FeaturePacks  
> CS: Warning: ViewportsTutorial  
> CS: Warning: BlueprintInterfacesEditorOverview  
> CS: Warning: BlueprintMacroLibrariesEditorOverview  
> CS: Warning: ClassBlueprintsEditorOverview  
> CS: Warning: LevelBlueprintEditorOverview  
> CS: Warning: Tutorial\_BP\_Class  
> CS: Warning: Tutorial\_BP\_Interface  
> CS: Warning: Tutorial\_BP\_MacroLib  
> CS: Warning: … … etc etc loaded all blueprints…

---

<div class="post-metadata">

**Author:** ![FinalRockstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/finalrockstar/32/88718_2.png) [@FinalRockstar](https://forums.unrealengine.com/u/FinalRockstar)\
**Post date:** [April 11, 2021, 5:55pm UTC](https://forums.unrealengine.com/t/loading-blueprint-from-c/212630/14 "2021-04-11T17:55:53Z")

</div>

Yes on doing blueprint it works. It also loads resource Manager
