🏝️Place On Surface

Place objects on terrains and colliders

Use this as both a creative tool for building scenes, as well as an animation behavior to dynamically place objects. More than just working with terrains, objects may also be placed on colliders of all types using raycasts.

Place On Surface has two read-only channels, one for the final placed position and another for rotation. The latter is optional and may be hidden if not in use.

Place On Surface Editor

Select the object to view its settings in the Inspector.

For common features, please refer to Menu Bar and Update Settings.

Editor vs Runtime

If you are using Place On Surface in the editor only, the runtime mode can be set in the menu bar to Editor Only. This destroys the component at runtime but preserves it in edit mode.

Refresh All

Use this button to bulk update all instances of Place On Surface throughout the scene.

Use Refresh All after making changes to a terrain or the scene layout to update all placed items. This only affects Place On Surface instances currently active.

Placement Mode

Objects may be placed either using Raycast or Sample Terrain Height.

Sample Terrain Height

This mode samples the height of the terrain using Unity's built-in method. If placement is only on terrains and the surface orientation isn't needed (i.e. the object doesn't need to rotate to the surface) then this mode is a more optimal choice than using Raycast.

This mode has a simpler setup with fewer options.

Raycast

Raycasting provides the best results since it can compute rotation and includes all terrains and colliders (according to the Layer Mask). However raycasting is computationally intensive so should be used sparingly.

The frequency of the raycast may be changed in the Update Settings.

Optimization

When using Raycast mode, it is recommended to change the update method to Fixed Update, so that it updates according to the framerate for physics. This reduces the number of raycasts overall and improves performance.

For more information, see Raycast and Fixed Timestep in the Unity documentation.

Layer Mask

Restricts placement to only include terrains and colliders on the specified layers. This option is only available when using Raycast mode.

Avoid Same Object Collisions

Please refer to the Unity documentation for Layers and Layer Masks.

Raycast Direction

Sets the direction of the ray, originating from the current position plus any offsets. This field expects a normalized value (all vectors adding up to 1). Normalization is automatically applied to ensure the length of the ray is consistent.

Use Transform

Enable this to orient the raycast direction towards another object in the scene. This is helpful to make an object follow the contours of an object from all angles.

Projecting Objects Onto Surfaces

Rays may be cast in any direction making it possible to place objects on surfaces from any angle simply by changing the Raycast Direction. This can also be used to make an object stick to another or to traverse the surfaces of multiple objects.

Raycast Offset

Offsets the starting point of the raycast along the direction vector.

Each raycast is like an arrow shot into the scene, detecting the first object hit. To ensure that the raycast starts at a far enough distance away from the target, an offset is often needed.

The X and Z axis offsets can also be used in special cases where the raycast needs to be shifted off center from the current position.

+ Terrain Height

If Terrain Height is enabled (recommended) the raycast is automatically offset by the height of the terrain so that the ray is always projected from a higher point. Otherwise, if the ray starts too low, it misses the terrain altogether and fails to place the object.

Failing to Place

Raycast Distance

Sets the total length of the raycast. Only objects within this distance from the raycast origin may be detected. Placement occurs on the first collider or terrain hit. Adjust the distance according to the scale and needs of your scene.

Apply to Transform

Placement may be placed on the same object (current transform) or applied to the transform of another object. Which setup you use depends on the desired results.

Separate Transforms (placer vs item placed)

Applying results to a separate transform means that the current transform remains in place and is unaffected by placement. Since the origin of the raycast is based on the current transform, this can make placement more stable and avoid runaway conditions. This setup is also more conducive to using Place On Surface as a construction tool.

Use Rigidbody

If enabled, placement is applied to the rigidbody component instead of the transform. This method of moving the object produces the same results visually, however allows the object to correctly interact with physics.

Physics only works at runtime, so enter Play Mode to see final results. In edit mode, the transform is used instead as a proxy.

Position

Enables positioning for all or individual axes to constrain placement to a specific axis or plane.

Smooth Time

Applies temporal smoothing based on the time seconds. Use the Max field to set the max value of the slider.

Smoothing is only applied while playing in Timeflow. When rewinding or jumping in time, position is applied directly to avoid odd placement results.

Height Offset

Adds an offset to the placement position on the Y axis.

World Limits

Enable limits to constrain the placement of an object within a bounding region in world coordinates.

X and Z are disabled automatically by the Enable Position states as shown in the example earlier.

Position limits are only enforced on each axis checked and according to Enable Position.

Rotation

The rotation channel is hidden from the Timeflow view if the Rotation mode is None.

Face Surface Hit

If enabled, the object orients to look at the point on the surface hit. Otherwise if off, the rotation matches the surface normal. This option is useful for projecting objects onto the surface of other objects, orienting to the projection angle rather than surface.

Smooth Time

Applies temporal smoothing over the specified time (in seconds). A longer time results in slower rotation, while a small time value responds more quickly.

Smoothing is only applied while playing in Timeflow. Whenever rewinding or skipping time, rotation is applied directly to avoid anomalies with smoothing.

Gizmos

If enabled and using Raycast mode, the current direction and length is displayed using the display color selected.

Note that the Gizmos color is the same as the channel color in the Timeflow view.

Debug Ray

Draws lines in the color chosen precisely where raycasts are performed in 3D space. Each line remains visible for the duration specified.

Raycasts are drawn in red while playing the timeline. The thicker cyan line is the current direction and length.

Additional Notes

Fixed Update

Since raycasting is a physics feature, it is advised for optimal performance to use Fixed Update, set in the Update Settings. This reduces the number of raycasts to the frame rate defined by Fixed Timestep in Project Settings under Time.

Using Explicit Update

To place an object just once and prevent it from automatically updating, the update mode for the Place On Surface behavior may be set to Explicit in the Update Settings.

Setting update to Explicit means that Place On Surface will not recalculate until you press the Refresh button.

Last updated