# Cannot Spawn actor using c++

**URL:** <https://forums.unrealengine.com/t/cannot-spawn-actor-using-c/489485>\
**Category:** Asset Creation\
**Tags:** spawn-actor-from-cla, unreal-engine, question\
**Created:** [October 3, 2021, 4:29pm UTC](https://forums.unrealengine.com/t/cannot-spawn-actor-using-c/489485 "2021-10-03T16:29:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![galuodo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@galuodo](https://forums.unrealengine.com/u/galuodo)\
**Post date:** [October 3, 2021, 4:29pm UTC](https://forums.unrealengine.com/t/cannot-spawn-actor-using-c/489485/1 "2021-10-03T16:29:36Z")

</div>

HI all,  
I am reading _Leaning c++ by Creating Games with UE4_, when i am trying spawn a bullet, it fails.

```
            FVector fwd = GetActorForwardVector();
	FVector nozzle = GetMesh()->GetBoneLocation("RightHand");
	nozzle += fwd * 155;// move it fwd of the monster so it doesn't 
		// collide with the monster model 
	FVector toOpponent = thing->GetActorLocation() - nozzle;
	toOpponent.Normalize();
	ABullet* bullet = GetWorld()->SpawnActor<ABullet>(
		BPBullet, nozzle, RootComponent->GetComponentRotation());

	if (bullet)
	{
		bullet->Firer = this;
		bullet->ProxSphere->AddImpulse(
			toOpponent * BulletLaunchImpulse);
		GEngine->AddOnScreenDebugMessage(0, 5.f,
	}
	else
	{
		GEngine->AddOnScreenDebugMessage(0, 5.f,
			FColor::Yellow, "monster: no bullet actor could be spawned. is the bullet overlapping something ? ");

```

}

the spawn return null all the time. then I clear the static mesh on bullet, it can spawn correctly.  
Is there something wrong?

---

<div class="post-metadata">

**Author:** ![andrew-r-lukasik](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/andrew-r-lukasik/32/780005_2.png) [@andrew-r-lukasik](https://forums.unrealengine.com/u/andrew-r-lukasik)\
**Post date:** [October 3, 2021, 5:07pm UTC](https://forums.unrealengine.com/t/cannot-spawn-actor-using-c/489485/2 "2021-10-03T17:07:56Z")

</div>

What is `BPBullet` exactly?

---

<div class="post-metadata">

**Author:** ![galuodo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@galuodo](https://forums.unrealengine.com/u/galuodo)\
**Post date:** [October 3, 2021, 5:17pm UTC](https://forums.unrealengine.com/t/cannot-spawn-actor-using-c/489485/3 "2021-10-03T17:17:40Z")

</div>

it defines as

```
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MonsterProperties)
UClass * BPBullet;

```

A blue print class of the bullet:

 ![349832-screenshot-20211004-011700.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/7/7/977e8e00106fb903daf2885d8bdbaefc861244ca.png)

---

<div class="post-metadata">

**Author:** ![grouptout](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@grouptout](https://forums.unrealengine.com/u/grouptout)\
**Post date:** [October 3, 2021, 5:46pm UTC](https://forums.unrealengine.com/t/cannot-spawn-actor-using-c/489485/4 "2021-10-03T17:46:53Z")

</div>

CPP:

```
if (IsValid(BPBullet))
{
	GetWorld()->SpawnActor<ABullet>(BPBullet, GetActorTransform());
}

```

H:

```
UPROPERTY(EditAnywhere, BlueprintReadWrite)
	TSubclassOf<ABullet> BPBullet;

```

BP:

![349822-изображение-2021-10-03-204641.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/8/0/f80806aae53bbfe308cb05c904db0d3d07f16355.png)
