# Spawn Blueprint from path in c++

**URL:** <https://forums.unrealengine.com/t/spawn-blueprint-from-path-in-c/394875>\
**Category:** Blueprint\
**Tags:** unreal-engine, Scripting, Blueprint, question, CPP\
**Created:** [May 28, 2017, 12:46pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-path-in-c/394875 "2017-05-28T12:46:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gundz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gundz](https://forums.unrealengine.com/u/gundz)\
**Post date:** [May 28, 2017, 12:46pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-path-in-c/394875/1 "2017-05-28T12:46:23Z")

</div>

Hi,

I’m trying to spawn an Blueprint Actor directly from C++ code, i found many answers to this question but none works (the only one was to add \_C at the end of the path, but it doesn’t work when the game is packaged

I Have a “TargetItem” actor class and a blueprint parented from it. And i want to spawn it from another class

Spawner.h

```
UPROPERTY()
TSubclassOf<class AKryptos_TargetItem>	targetItemClass;

```

Spawner.cpp (in constructor)

```
ConstructorHelpers::FObjectFinder<UBlueprint> ItemBlueprint(TEXT("Blueprint'/Kryptos/BP/Targets/BP_TargetItem.BP_TargetItem'"));
if (ItemBlueprint.Object)
{
    UE_LOG(LogTemp, Warning, TEXT("OK"));
    targetItemClass = (UClass *)ItemBlueprint.Object;
}
else
{
    UE_LOG(LogTemp, Warning, TEXT("NOT OK"));
}

```

Spawner.cpp (in another function)

```
AKryptos_TargetItem *item = _world->SpawnActor<AKryptos_TargetItem>(targetItemClass, vectors[i], FRotator(0, 0, 0), FActorSpawnParameters())
if (item)
{
    UE_LOG(LogTemp, Warning, TEXT("Actor spawned !");
}

```

For now i get this error when i try to spawn: `SpawnActor failed because Class is not an actor class`

I’m working on a plugin and i get the path from the right click “Get reference”

Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![Nachtmahr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nachtmahr](https://forums.unrealengine.com/u/Nachtmahr)\
**Post date:** [May 28, 2017, 1:04pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-path-in-c/394875/2 "2017-05-28T13:04:20Z")

</div>

static ConstructorHelpers::FClassFinder\<AKryptos\_TargetItem\> ItemClass(TEXT("/Game/Kryptos/BP/Targets/BP\_TargetItem"));  
if (ItemClass.Class != NULL)  
{  
targetItemClass= ItemClass.Class;  
}

Edit: sry just saw you do a Plugin you might not need “/Game/” in your Path =)

---

<div class="post-metadata">

**Author:** ![gundz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gundz](https://forums.unrealengine.com/u/gundz)\
**Post date:** [May 28, 2017, 4:14pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-path-in-c/394875/3 "2017-05-28T16:14:53Z")

</div>

Thanks worked perfectly !

---

<div class="post-metadata">

**Author:** ![gundz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gundz](https://forums.unrealengine.com/u/gundz)\
**Post date:** [May 29, 2017, 12:43pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-path-in-c/394875/4 "2017-05-29T12:43:31Z")

</div>

Hi,

After packaging my game i get an error (for the two classes where i used your solution) on launch.

It work fine in-editor or in-editor standalone.

`Error: CDO Constructor (Kryptos_TargetDisplayer): Failed to find /Kryptos/BP/Targets/BP_TargetItem.BP_TargetItem_C`

---

<div class="post-metadata">

**Author:** ![Nachtmahr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nachtmahr](https://forums.unrealengine.com/u/Nachtmahr)\
**Post date:** [May 29, 2017, 1:45pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-path-in-c/394875/5 "2017-05-29T13:45:27Z")

</div>

Can you give me a Up-to-date snippet of your Code please?

---

<div class="post-metadata">

**Author:** ![gundz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gundz](https://forums.unrealengine.com/u/gundz)\
**Post date:** [May 29, 2017, 1:52pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-path-in-c/394875/6 "2017-05-29T13:52:22Z")

</div>

I tried to package the plugin in a new project.  
Still the same issue, and a lot of warning disapeared, but i have still a lot.

I will try to solve them before maybe it will fix the issue.

---

<div class="post-metadata">

**Author:** ![gundz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gundz](https://forums.unrealengine.com/u/gundz)\
**Post date:** [May 29, 2017, 2:14pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-path-in-c/394875/7 "2017-05-29T14:14:01Z")

</div>

I was able to fix all the warning and my CDO Constructor issue by simply changing values to:

`[pluginName].uplugin` file

` "Type": "Runtime", "LoadingPhase": "PreDefault"`

I set the post back to solved, thanks again for your quick reply !

---

<div class="post-metadata">

**Author:** ![Talad](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Talad](https://forums.unrealengine.com/u/Talad)\
**Post date:** [April 2, 2018, 10:38am UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-path-in-c/394875/8 "2018-04-02T10:38:18Z")

</div>

Hi,  
I had the same problem, and I found two possible solutions.

1. If your actor is created in the Unreal Editor, then you can simply spawn it by code like this:

The pre-requisite is that your actor is replicated. Please note that actors deriving from AActor are not replicated by default, so you need to add in their constructor:

bReplicates = true;

or within the editor you should flag your actor as “Replicates”. It is one of the properties in the details panel.

1. If you want to create your actor completely within C++, and you have only the StaticMesh and the Material in the Editor (this was my case), you can create it like this:

Also in this case the pre-requisite is that your actor is replicated. Same case for case 1.

If your actor is invisible client side, means you didn’t replicate it, or you didn’t set the position properly. Please note the SetWorldLocation call despite the fact you are already giving the location in the spawnactor command. For me it works only if I call explicitely SetWorldLocation

---

<div class="post-metadata">

**Author:** ![Kulagin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kulagin](https://forums.unrealengine.com/u/Kulagin)\
**Post date:** [March 25, 2025, 7:50pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-path-in-c/394875/9 "2025-03-25T19:50:30Z")

</div>

```auto
#include "UObject/ConstructorHelpers.h"

		FString AssetPath = TEXT("/Game/Blueprints/BP_TargetItem");
		UClass* BP_TargetItemClass = ConstructorHelpersInternal::FindOrLoadClass(AssetPath, UObject::StaticClass());

```

This is the most universal and easy to use way to load blueprint classes. Works in constructors and outside. You don’t need the `.BP_TargetItem_C` after package path.

You need to add CoreUObject to the dependencies of your project.
