# SpawnActor spawns in wrong location

**URL:** <https://forums.unrealengine.com/t/spawnactor-spawns-in-wrong-location/316577>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [April 27, 2015, 2:16pm UTC](https://forums.unrealengine.com/t/spawnactor-spawns-in-wrong-location/316577 "2015-04-27T14:16:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pancakez](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pancakez](https://forums.unrealengine.com/u/Pancakez)\
**Post date:** [April 27, 2015, 2:16pm UTC](https://forums.unrealengine.com/t/spawnactor-spawns-in-wrong-location/316577/1 "2015-04-27T14:16:41Z")

</div>

Hello. Its my second day with Unreal, I am following tutorial on

> **[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 — https://unrealcommunity.wiki/! You will be able to find content from...

SpawnActor spawns the actor in the same, wrong location no matter what paramaters the function gets  
Basically i spawn the actor every second, and it should spawn it in random locations. I even tried hardcoding the spawn XYZ but it does not work… The spawn location seems to be (0,0,0) by the way.

```
FActorSpawnParameters SpawnParams;  
SpawnParams.Owner = this;  
SpawnParams.Instigator = Instigator;  
//SpawnParams.  
// Get a random location to spawn at  
FVector SpawnLocation = GetRandomPointInVolume();  
//even when i hardcoded some values it still spawned in the same wrong xyz  
/*SpawnLocation.X = -850.0f;  
SpawnLocation.Y = 0.0f;  
SpawnLocation.Z = 1000.0f;*/  
// Get a random rotation for the spawned item  
FRotator SpawnRotation;  
SpawnRotation.Yaw = FMath::FRand() * 360.f; // this should rotate the mesh, but i see the mesh in vertical position all the time  
SpawnRotation.Pitch = FMath::FRand() * 360.f;  
SpawnRotation.Roll = FMath::FRand() * 360.f;  

GetWorld()->SpawnActor(WhatToSpawn, SpawnLocation, SpawnRotation, SpawnParams);

```

What is wrong? Im using EU 4.7.6, the tutorial is pretty otudated but i dont think thats the case. Thanks in advacne for help

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [April 27, 2015, 6:19pm UTC](https://forums.unrealengine.com/t/spawnactor-spawns-in-wrong-location/316577/2 "2015-04-27T18:19:15Z")

</div>

Hi Pancakez,

The code that you have provided (other than the hardcoded numbers that you added) look the exact same as the code provided in the video so I am expecting that the issue is elsewhere. Could you provide me with the full .cpp and .h files that you are using to spawn this object?

As a tip for posting code, you can use the ‘Code Sample’ button (Or ctrl+K on a windows keyboard) to post code while keeping syntax intact. You can also upload the files if you would like.

-

---

<div class="post-metadata">

**Author:** ![Pancakez](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pancakez](https://forums.unrealengine.com/u/Pancakez)\
**Post date:** [April 27, 2015, 7:08pm UTC](https://forums.unrealengine.com/t/spawnactor-spawns-in-wrong-location/316577/3 "2015-04-27T19:08:30Z")

</div>

Thanks for reply. I actually created second, separate project with Third Person C++ starter content template. The only class added by me is Actor “SomeThing”. The spawn is bugged in exactly the same way.  
Thats the code http:///sGiSgrEY

I noticed that changing RootComponent to mesh and getting rid of CollisionComponent fixes the spawn issue ( but why?? ). Everytime i press E, new, rotated brick appears falling from the sky, but the ground (the floor) doesnt stop it (i want some kind of pickup item like in that tutorial so they should stay on ground), but the character collides as i move through the falling bricks.  
The code with good spawn but collision problem http:///ZE3b4EHG

I finally managed to fix that and make sphere as the collision component  
The solution was to use CollisionComponent, set physics for it and not for the mesh and BaseCollisionComponent-\>SetCollisionProfileName(“BlockAll”);

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [April 27, 2015, 9:00pm UTC](https://forums.unrealengine.com/t/spawnactor-spawns-in-wrong-location/316577/4 "2015-04-27T21:00:40Z")

</div>

Hi Pancakez,

It took me quite a bit of looking through your code but I believe I’ve found the issue.

In the code that you provided where the object has collision but constantly spawns at 0,0,0, you’re adding a collision component and then making that the root component and attaching the mesh to it. The collision volume is going to default to 0,0,0 and will not be changed by the function that you are calling to spawn the object.

In the second bit of code you provided you had set the Mesh as the root component, which does not have a default position so your object is spawning where intended.

I would suggest using the same code you used where the object actually collided but make the RootComponent the mesh and attach the collision component to the mesh itself.

Have a nice day

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [April 27, 2015, 9:01pm UTC](https://forums.unrealengine.com/t/spawnactor-spawns-in-wrong-location/316577/5 "2015-04-27T21:01:28Z")

</div>

Ah, just as I post my answer, I see your edit. Good job figuring it out!

---

<div class="post-metadata">

**Author:** ![Reuben\_Ward](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Reuben\_Ward](https://forums.unrealengine.com/u/Reuben_Ward)\
**Post date:** [April 23, 2017, 3:09pm UTC](https://forums.unrealengine.com/t/spawnactor-spawns-in-wrong-location/316577/6 "2017-04-23T15:09:35Z")

</div>

Hi,  
Why would the collision volume default to 0,0,0? That doesn’t make any sense to me, the SpawnActor function should be setting the location of the actor, why is it this way?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [June 1, 2017, 5:32pm UTC](https://forums.unrealengine.com/t/spawnactor-spawns-in-wrong-location/316577/7 "2017-06-01T17:32:22Z")

</div>

Hello ,

I think you’re right, I was taking a look over this again (I believe this post was right after I started here actually, so I wasn’t all that familiar with the spawn functions in UE4) and it doesn’t make any sense that it would spawn at 0,0,0. Testing it out myself in 4.16, it seems to spawn at the correct location so it was either incorrect before or has been fixed in the 2 year span since this was reported.
