# Spawn Blueprint from C++

**URL:** <https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316>\
**Category:** Editor Scripting\
**Tags:** inventory, unreal-engine, spawning-actors, CPP, Blueprint, question\
**Created:** [June 7, 2014, 10:11pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316 "2014-06-07T22:11:15Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnxGotta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AnxGotta](https://forums.unrealengine.com/u/AnxGotta)\
**Post date:** [June 7, 2014, 10:11pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/1 "2014-06-07T22:11:15Z")

</div>

Hello all,

I am trying to spawn a Blueprinted object in my game and I cant seem to get this to work.

I have “Items” that are partially code and partially Blueprint. When they are added to the player inventory system, they need to pass the Path to the Blueprint or something to the inventory manager that will be maintained. I then destroy the actual Item Actor. I spawn them again when they are dropped or used (removed from inventory).

This system is dynamic, I pick up items, drop them, etc.

I have the framework coded for the inventory management and now I am trying to figure out what to give it so that I can spawn the Item from the Item Blueprint.

I saw a few other questions like this, specifically [THIS](https://answers.unrealengine.com/questions/2690/c-can-you-spawn-from-a-blueprint-without-it-being.html) one but I am still unable to get this to work.

Any advice would be very helpful.

Thanks.

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [June 7, 2014, 10:54pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/2 "2014-06-07T22:54:37Z")

</div>

You can’t, you would need to get asset but it no quite efficient of doing this

Create base class “AItem” in C++, implement all things you need for a item and make you inventory satisfied just with Item, then make classes based of AItem class which have code for actual items. Now i assume you made inventory system which use pickup and inventory system sepretly (which is something you don’t need to do you can simply add and remove mesh component), you could store UClass objects of classes (you can get i via GetClass() or StaticClass()) and span object in C++ via ()-\>SpawnActor(UClass);

---

<div class="post-metadata">

**Author:** ![AnxGotta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AnxGotta](https://forums.unrealengine.com/u/AnxGotta)\
**Post date:** [June 7, 2014, 11:49pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/3 "2014-06-07T23:49:20Z")

</div>

Hi ,

Yeah, I did this with just the AItem class… all in C++ except for the Mesh Component. I assign the Mesh in the Blueprint. That is where this problem came from. I kept the StaticClass() in the Inventory and then when the player drops the AItem from inventory I spawn it again but it had no Mesh because it was assigned in the Blueprint.

So you think I should just assign the Item StaicMeshComponent in C++ and then just do it with the StaticClass() passing and spawning?

Kind of like answered [HERE](https://answers.unrealengine.com/questions/13555/question-apply-static-mesh-to-staticmesh-component.html)?

---

<div class="post-metadata">

**Author:** ![AnxGotta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AnxGotta](https://forums.unrealengine.com/u/AnxGotta)\
**Post date:** [June 8, 2014, 12:31am UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/4 "2014-06-08T00:31:38Z")

</div>

Well, I just surprised myself. I guess I got the break I needed while waiting for help because I got it to work perfect.

Here’s how for anyone else that comes across this:

I have the majority of my Item class in C++ with a few things in a Blueprint. In the editor I drop the Blueprinted Item all over the map for my player to pick up. When I interact with the item, my inventory system stores the class, in my case the Blueprinted class, of the particular item that I picked up in my inventory (along with other info for book keeping) and destroys the actor in game. When my player equips or drops the item, I simply spawn the Blueprint Actor into the game and viola, new Actor from Blueprint spawned from C++ dynamically.

In my Item class header file I made a pointer to hold the Blueprinted class name:

AItem.h

```
TSubclassOf<class AItem> MyItemBlueprint;

```

Then in the Constructor for the AItem I grab the class of the blueprint and assign it to the `MyItemBlueprint` variable:

AItem.cpp

```
AItem::AItem(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

	// do things

...

	static ConstructorHelpers::FObjectFinder<UBlueprint> ItemBlueprint(TEXT("Blueprint'/Game/Items/Blueprints/BP_ItemTest.BP_ItemTest'"));
	if (ItemBlueprint.Object){
		MyItemBlueprint = (UClass*)ItemBlueprint.Object->GeneratedClass;
	}

}

```

Then, when I want to spawn this AItem later, as long as I have the value from `MyItemBlueprint` I can spawn it in the game like this:

```
UWorld* const World = ();
if (World){
    FActorSpawnParameters SpawnParams;
    SpawnParams.Instigator = this;
    AItem* DroppedItem = World->SpawnActor<ASurItem>(MyItemBlueprint, Location, Rotation, SpawnParams);
    if (DroppedItem){
        DroppedItem->DoTheThings();
    }
}

```

Hopefully that helps someone else!

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [June 8, 2014, 12:58am UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/5 "2014-06-08T00:58:24Z")

</div>

did you try GetClass()?

---

<div class="post-metadata">

**Author:** ![AnxGotta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AnxGotta](https://forums.unrealengine.com/u/AnxGotta)\
**Post date:** [June 8, 2014, 1:03am UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/6 "2014-06-08T01:03:16Z")

</div>

I did not. I got it working the way above. I’m not sure if the spawning method of inventory is best, but I plan on having stacks of items in inventory up to 50 or more… Seems best not to Hide and maintain actors in the level.

---

<div class="post-metadata">

**Author:** ![bach\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bach\_1](https://forums.unrealengine.com/u/bach_1)\
**Post date:** [June 8, 2014, 9:47am UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/7 "2014-06-08T09:47:11Z")

</div>

Thanks @AnXgotta that worked well for me. Also a there a great example an snippet here [A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums](https://wiki.unrealengine.com/Templates_in_C%2B%2B)

---

<div class="post-metadata">

**Author:** ![AnxGotta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AnxGotta](https://forums.unrealengine.com/u/AnxGotta)\
**Post date:** [June 8, 2014, 10:36am UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/8 "2014-06-08T10:36:12Z")

</div>

I’m glad it helped and thanks for pointing out that resource, I definitely missed it.

---

<div class="post-metadata">

**Author:** ![Jesse\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Jesse\_1](https://forums.unrealengine.com/u/Jesse_1)\
**Post date:** [August 24, 2014, 1:58am UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/9 "2014-08-24T01:58:18Z")

</div>

Hi AnXgotta, I am attempting to spawn blueprinted actors in code but cannot see them. I know that the actors are getting spawned, I just cannot see them at all. I am not sure if it is the same problem you were having with the static mesh component. Were you able to spawn your items with their static meshes? and if you were, do you have any tips on getting them to spawn with the static mesh that is attached to the blueprint?

---

<div class="post-metadata">

**Author:** ![AnxGotta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AnxGotta](https://forums.unrealengine.com/u/AnxGotta)\
**Post date:** [August 24, 2014, 1:24pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/10 "2014-08-24T13:24:24Z")

</div>

Hey Jesse, I was able to spawn them with static meshes. I would check the spawn location of the object and make sure it is where you think it is. I would then ensure that the object isn’t hidden in any way.

---

<div class="post-metadata">

**Author:** ![nkey](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@nkey](https://forums.unrealengine.com/u/nkey)\
**Post date:** [September 27, 2015, 7:33pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/11 "2015-09-27T19:33:04Z")

</div>

> **[Dynamic blueprints loading](https://forums.unrealengine.com/questions/89482/dynamic-blueprints-loading.html)**
>
> Hello, I wrote a func that finds an asset(blueprint in my case) by name, loads it and returns it like TSubcalssOf. It really usefull for spawning object in blueprints. TSubclassOf UShipUtils::GetShip(const FString & name) { auto ships =...

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6fcbe82e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6fcbe82e](https://forums.unrealengine.com/u/anonymous_user_6fcbe82e)\
**Post date:** [January 15, 2016, 11:07am UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/12 "2016-01-15T11:07:43Z")

</div>

What is ‘ASurItem’ that just comes out of the blue it seems… shouldn’t that be AItem ?

---

<div class="post-metadata">

**Author:** ![AnxGotta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AnxGotta](https://forums.unrealengine.com/u/AnxGotta)\
**Post date:** [January 15, 2016, 4:41pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/13 "2016-01-15T16:41:36Z")

</div>

This is a bit old but if I remember correctly, it’s a child class of AItem

---

<div class="post-metadata">

**Author:** ![BitRot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bitrot/32/498776_2.png) [@BitRot](https://forums.unrealengine.com/u/BitRot)\
**Post date:** [August 5, 2019, 2:13pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/14 "2019-08-05T14:13:40Z")

</div>

For those coming here from google, I was able to do this in a much simpler way:

```
// Step 1. Declare a property of type blueprint
UPROPERTY(EditAnywhere, Category = Players, meta = (AllowPrivateAccess = "true"))
TSubclassOf<class AActor> PlayerBlueprintType;

// Step 2. Wherever you need a UClass * reference for that blueprint (like SpawnActor)
AActor *player = ()->SpawnActor(PlayerBlueprintType.Get(), &playerStart->GetActorTransform(), params);

```

Just make sure you’re checking that PlayerBlueprintType (in this example) is non-null!

---

<div class="post-metadata">

**Author:** ![Rudel2003](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rudel2003](https://forums.unrealengine.com/u/Rudel2003)\
**Post date:** [September 17, 2019, 11:02pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/15 "2019-09-17T23:02:49Z")

</div>

I do not understand the solution.  
You want spawn the item from another actor (Player or Inventory). How this actor has the value of MyItemBlueprint?

---

<div class="post-metadata">

**Author:** ![AnxGotta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AnxGotta](https://forums.unrealengine.com/u/AnxGotta)\
**Post date:** [September 18, 2019, 12:14pm UTC](https://forums.unrealengine.com/t/spawn-blueprint-from-c/285316/16 "2019-09-18T12:14:32Z")

</div>

When you extend this c++ class in blueprint, that variable will appear in the blueprint and you set it in there. IIRC, it will be exposed as a drop down selector.
