# Programmatically snapping spawned meshes to surface

**URL:** <https://forums.unrealengine.com/t/programmatically-snapping-spawned-meshes-to-surface/306517>\
**Category:** Blueprint\
**Tags:** spawn, unreal-engine, UE4, CPP, question\
**Created:** [February 10, 2015, 9:02am UTC](https://forums.unrealengine.com/t/programmatically-snapping-spawned-meshes-to-surface/306517 "2015-02-10T09:02:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![drone.ah](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@drone.ah](https://forums.unrealengine.com/u/drone.ah)\
**Post date:** [February 10, 2015, 9:02am UTC](https://forums.unrealengine.com/t/programmatically-snapping-spawned-meshes-to-surface/306517/1 "2015-02-10T09:02:45Z")

</div>

Hello,

We would like to be able to spawn a mesh and allow the player to move it around, but keep it attached to ground.

What would be the simplest way to achieve this?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_957a4452](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_957a4452](https://forums.unrealengine.com/u/anonymous_user_957a4452)\
**Post date:** [February 10, 2015, 10:38am UTC](https://forums.unrealengine.com/t/programmatically-snapping-spawned-meshes-to-surface/306517/2 "2015-02-10T10:38:25Z")

</div>

Hi,

When you attach actor to another actor with no physics simulation, attached actor has no physics too, even if it has checked option Simulate Physics. Describe please what behavior you would like to achieve. If you want to get actor always on same height, you can try to lock z-axis (property Locked Axis in Physics category).

Best regards,

---

<div class="post-metadata">

**Author:** ![drone.ah](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@drone.ah](https://forums.unrealengine.com/u/drone.ah)\
**Post date:** [February 10, 2015, 4:39pm UTC](https://forums.unrealengine.com/t/programmatically-snapping-spawned-meshes-to-surface/306517/3 "2015-02-10T16:39:07Z")

</div>

We are looking to allow the player to spawn a building onto a map. While placing the building, it should be “rooted” to the ground while it is moved around and finally placed. What would be the best way of doing this?

Thanks in advance for your help

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_957a4452](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_957a4452](https://forums.unrealengine.com/u/anonymous_user_957a4452)\
**Post date:** [February 12, 2015, 3:01pm UTC](https://forums.unrealengine.com/t/programmatically-snapping-spawned-meshes-to-surface/306517/4 "2015-02-12T15:01:29Z")

</div>

Hi drone.ah,

Sorry for a long delay. I see what you are talking about now. For snapping spawned meshes to surface, you can try next:

- When ground is flat: Z-value is const. and it is possible to get it from first tap trace or from ground actor.
- Ground is landscape: I think the simplest way is to get Z-value from trace or you can retrieve it from height map (for example like here [Accessing pixel values of Texture2D - Asset Creation - Epic Developer Community Forums](https://answers.unrealengine.com/questions/25594/accessing-pixel-values-of-texture2d.html#answer-73443))

Best regards,

---

<div class="post-metadata">

**Author:** ![drone.ah](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@drone.ah](https://forums.unrealengine.com/u/drone.ah)\
**Post date:** [February 14, 2015, 12:19pm UTC](https://forums.unrealengine.com/t/programmatically-snapping-spawned-meshes-to-surface/306517/5 "2015-02-14T12:19:32Z")

</div>

I was hoping there was some way to use the physics to determine how to place it, but your solution should be fine… Thank you… 😃
