# Why is my actor location 0 after spawning at runtime?

**URL:** <https://forums.unrealengine.com/t/why-is-my-actor-location-0-after-spawning-at-runtime/282214>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [May 1, 2014, 3:49pm UTC](https://forums.unrealengine.com/t/why-is-my-actor-location-0-after-spawning-at-runtime/282214 "2014-05-01T15:49:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![iniside](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/iniside/32/866315_2.png) [@iniside](https://forums.unrealengine.com/u/iniside)\
**Post date:** [May 1, 2014, 3:49pm UTC](https://forums.unrealengine.com/t/why-is-my-actor-location-0-after-spawning-at-runtime/282214/1 "2014-05-01T15:49:22Z")

</div>

I’m trying to spawn actor in game. For testing it is very simple:

```
	HitLocation.ImpactPoint.Z += Height;
	FTransform SpawnTM(FRotator(0, 0, 0), HitLocation.ImpactPoint);
	
	ARPGProjectileSpawner* spawner = Cast<ARPGProjectileSpawner>(UGameplayStatics::BeginSpawningActorFromClass(PowerOwner, effectActor, SpawnTM));
	if (spawner)
	{
		spawner->SetActorLocation(HitLocation.ImpactPoint);
		spawner->SetActorRelativeLocation(HitLocation.ImpactPoint);
		UGameplayStatics::FinishSpawningActor(spawner, SpawnTM);
	}
}

```

It works, and actor spawn in correct position.

No in that spawned actor I try to get location:

```
FVector currentLocation = GetActorLocation();
DrawDebugSphere((), currentLocation, Radius, 32, FColor::Yellow, false, 10.0f);

```

And GetActorLocation() return 0 vector.

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 1, 2014, 3:53pm UTC](https://forums.unrealengine.com/t/why-is-my-actor-location-0-after-spawning-at-runtime/282214/2 "2014-05-01T15:53:29Z")

</div>

#Regular SpawnActor?

For comparison, what happens if you use regular ole’ SpawnActor?

```
FActorSpawnParameters SpawnInfo;
SpawnInfo.bNoCollisionFail = true;
SpawnInfo.Owner = this;
SpawnInfo.Instigator = NULL;
SpawnInfo.bDeferConstruction = false;
 
return ()->SpawnActor<ARPGProjectileSpawner>(PowerOwner, HitLocation.ImpactPoint ,FRotator::ZeroRotator, SpawnInfo );

```

---

<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:** [May 1, 2014, 3:55pm UTC](https://forums.unrealengine.com/t/why-is-my-actor-location-0-after-spawning-at-runtime/282214/3 "2014-05-01T15:55:33Z")

</div>

Why are you using both SetActorLocation and SetActorRelativelocation in same time? Also ahy don’t you use ()-\>SpawnActor() to spawn?

---

<div class="post-metadata">

**Author:** ![iniside](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/iniside/32/866315_2.png) [@iniside](https://forums.unrealengine.com/u/iniside)\
**Post date:** [May 1, 2014, 4:04pm UTC](https://forums.unrealengine.com/t/why-is-my-actor-location-0-after-spawning-at-runtime/282214/4 "2014-05-01T16:04:36Z")

</div>

The issue with SpawnActor is, it can’t spawn Actor from TSubclassOf actor.

And I have some parts of my actor defined in blueprint.

---

<div class="post-metadata">

**Author:** ![iniside](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/iniside/32/866315_2.png) [@iniside](https://forums.unrealengine.com/u/iniside)\
**Post date:** [May 1, 2014, 4:30pm UTC](https://forums.unrealengine.com/t/why-is-my-actor-location-0-after-spawning-at-runtime/282214/5 "2014-05-01T16:30:58Z")

</div>

Ah nvm, my previous comment, It take SubclassOf.  
But the issue is, I need to spawn actor in Level, and when using SpawnActor, mesh I added to blueprint, doesn’t spawn.

But even if, the location vector is still 0.

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 1, 2014, 4:41pm UTC](https://forums.unrealengine.com/t/why-is-my-actor-location-0-after-spawning-at-runtime/282214/6 "2014-05-01T16:41:02Z")

</div>

I am not sure

but if you want to spawn a BP version of a base class

you should check out my templated spawn code

#Templated Spawn BP Wiki

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

---

<div class="post-metadata">

**Author:** ![iniside](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/iniside/32/866315_2.png) [@iniside](https://forums.unrealengine.com/u/iniside)\
**Post date:** [May 1, 2014, 5:02pm UTC](https://forums.unrealengine.com/t/why-is-my-actor-location-0-after-spawning-at-runtime/282214/7 "2014-05-01T17:02:29Z")

</div>

The BP spawned, but the issue of wrong location remained. It still spawn in 0,0,0 location.

---

<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:** [May 1, 2014, 5:30pm UTC](https://forums.unrealengine.com/t/why-is-my-actor-location-0-after-spawning-at-runtime/282214/8 "2014-05-01T17:30:39Z")

</div>

Hmmm this could be related to root component :\> again why call setactrorelativelocation?

---

<div class="post-metadata">

**Author:** ![iniside](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/iniside/32/866315_2.png) [@iniside](https://forums.unrealengine.com/u/iniside)\
**Post date:** [May 1, 2014, 7:06pm UTC](https://forums.unrealengine.com/t/why-is-my-actor-location-0-after-spawning-at-runtime/282214/9 "2014-05-01T19:06:57Z")

</div>

The issue was that I called even in wrong function, and it was called before location has been set.

It should have been called in OnConstruction.
