Terrain Prefab Placer

A terrain-aware prefab scattering tool with height filtering and randomized placement
for the Unity Editor by BigBuffaloBill.

Overview home

Author's Note on Expected Functionality: The author has written an important note about the intended scope, known limitations, and support expectations for this toolset. Please see Notes on Tool Intent, Status and Author Support before proceeding.

Terrain Prefab Placer is a Unity Editor tool that lets you scatter prefabs across your terrain with a single click — placed directly on the terrain surface. Placement is filtered by elevation, and randomized in position, rotation, and scale so the result looks natural rather than mechanical. Load up to ten prefabs into the tool’s slots, configure your placement settings, click Generate, and your objects appear in the scene immediately. When you’re done or want to try different settings, one click removes everything instantly.

Using a similar mechanism and workflow as the Terrain Height Spheres tool that this tool is packaged with, you can use the same style settings to place permanent objects at the desired height bands. The tool’s height filter gives you precise control over the height bands where your prefabs appear on the terrain. Two percentile sliders — bottom and top, each from 0 to 100 — let you target any slice of the terrain’s elevation range. Set the top slider to 30, for example, and your prefabs are placed only in the low valleys and flat ground. Set the bottom to 60 and the top to 100, and placement is restricted to the upper slopes and peaks. You can isolate any elevation band you need, from a broad mid-range to a narrow strip just a few percent wide.

Each placed object is randomized within a radius of half the grid spacing around its grid point, given a random Y rotation, and scaled by a tunable variance percentage — so even a single prefab produces a scattered, organic-looking result. When multiple prefabs are loaded, the tool picks randomly from your available slots on each placement. Generated objects are parented under a uniquely named container in the Hierarchy, making them easy to identify and manage. Your settings are not persisted between sessions, keeping each generation intentional and clean.


Key Features home


Requirements home


Installation home

Terrain Prefab Placer ships as part of the Terrain Height Visualizer & Prefab Placer package. Full installation instructions — including the Package Manager flow, import steps, and the complete post-import file structure — are covered in TerrainHeightVisualizerAndPrefabPlacer_Documentation.html in the parent directory.


Getting Started home

  1. Open the tool window: go to Tools > BBB > Terrain Prefab Placer in the Unity menu bar.
  2. Open a scene that contains at least one Terrain object.
  3. Assign at least one prefab to a slot in the Prefabs to Place section.
  4. Adjust Grid Spacing and Scale Variance % as desired.
  5. Optionally adjust the Bottom and Top Percentile sliders to restrict placement to a specific elevation range.
  6. Click Generate Objects. Your prefabs will appear in the scene parented under a uniquely named container.
  7. To remove the generated objects, click Remove Objects.

Detailed Usage Guide home

Opening the Window

Navigate to Tools > BBB > Terrain Prefab Placer. The window is a standard dockable Editor window with a minimum size of 300×400. The title is “Terrain Prefab Placer.”

Prefab Slots

The top section of the window shows ten Prefab slots (Prefab 1 through Prefab 10). Drag any prefab from the Project window into one or more slots. At least one slot must be filled before generation is allowed — the Generate Objects button is disabled otherwise, and a warning message is shown.

When multiple slots are filled, the tool picks randomly from all non-null slots on each individual placement. You can weight your prefab distribution by filling multiple slots with the same prefab.

Grid Spacing

Controls the distance in meters between placement grid points on both X and Z axes. Range: 0.01 m to 500 m. Each object is additionally offset randomly within a circle of radius half the grid spacing, so tighter grids produce denser, more overlapping scatter.

Performance note: Small grid spacing values produce a very large number of instantiated prefabs. Start with 100 m or higher and reduce as needed.

Scale Variance %

Applies a random scale multiplier to each placed object. Range: 0% to 50%. At 0% all objects are placed at their prefab’s default scale. At 20%, for example, each object is randomly scaled between 80% and 120% of its default. The multiplier is applied uniformly to all three axes.

Height Range Filter

The Bottom Percentile and Top Percentile sliders (0–100 each) restrict placement to a specific slice of your terrain’s elevation range, computed globally across all terrains in the scene.

Generating Objects

Click Generate Objects. The tool:

  1. Removes any previously generated container (same as clicking Remove Objects first).
  2. Finds all Terrain objects in the scene.
  3. Performs a first pass to compute the global min/max world-space height across all terrains.
  4. Creates a uniquely named container: __TerrainPrefabPlacer_Container_<GUID>.
  5. For each grid point within the percentile range, selects a random prefab, applies a random position offset within the grid cell, re-samples the terrain height at the randomized position, instantiates the prefab via PrefabUtility.InstantiatePrefab, applies random Y rotation and scale variance, and parents it to the container.

The Container

Each generation creates a new GameObject with a unique GUID-based name (e.g. __TerrainPrefabPlacer_Container_3f2a1b8c...). The window tracks and displays the most recently generated container name. Generate Objects always removes the currently tracked container before creating a new one — unless you have first baked it (see below).

Note: Unlike the Terrain Height Spheres tool, objects generated by this tool are saved to the scene. They are standard instantiated prefabs and will persist across Editor sessions unless explicitly removed.

Removing Objects

Click Remove Objects to destroy the currently tracked container and all its children. The button is disabled when no active container is tracked. If the container was renamed or deleted manually, Remove Objects will log a warning and clear its internal reference.

Baking Objects

Click Bake Current Objects to permanently detach the current container from the tool without destroying it. The container and all its children remain in the scene and are saved with it, but the tool forgets about them entirely — they become ordinary Hierarchy objects. After baking, the tool’s status resets to Inactive and the next Generate Objects call creates a fresh container, leaving the baked group untouched.

This allows you to build up layers of placed objects — for example, baking a group of trees, then generating and baking rocks at a different elevation band, without any pass disturbing the previous one.

If you later want to remove a baked group, find its container in the Hierarchy by its GUID name (e.g. __TerrainPrefabPlacer_Container_3f2a1b8c...) and delete it manually.


API Reference home

TerrainPrefabPlacer (class)

Namespace: BleBike.Editor

Inherits: UnityEditor.EditorWindow

Location: Editor/TerrainPrefabPlacer.cs

Description: The main Editor window class. Editor-only; not available at runtime.

Menu Items

Menu PathMethodDescription
Tools > BBB > Terrain Prefab Placer Open() Opens or focuses the Terrain Prefab Placer window.

Window Fields

FieldTypeDefaultDescription
_prefabsGameObject[10]all nullThe ten prefab slots. At least one must be assigned before generation.
_gridSpacingfloat100Distance in meters between grid sample points.
_scaleVariancePercentfloat10Random scale variance applied to each placed object (±%).
_bottomPercentilefloat0Lower bound of the height filter (0–100).
_topPercentilefloat100Upper bound of the height filter (0–100).

Key Private Methods

MethodDescription
Open()Static [MenuItem] — opens or focuses the window. Sets minimum size to 300×400.
OnEnable()Loads the last container name from EditorPrefs and calls FindExistingContainer().
OnGUI()Draws the full window UI: prefab slots, sliders, status, container name display, and Generate/Remove buttons.
HasAtLeastOnePrefab()Returns true if any slot in _prefabs is non-null. Used to gate the Generate button.
FindExistingContainer()Attempts GameObject.Find on the stored container name to restore active state after domain reload.
GenerateObjects()Removes any existing container, finds terrains, computes global height range, creates the GUID-named container, and delegates per-terrain placement to GenerateObjectsForTerrain.
GenerateObjectsForTerrain(Terrain, float, float, float, float)Iterates the grid for one terrain, applies the height filter, randomizes position and re-samples height, instantiates and configures each prefab, and returns the count placed.
GetRandomPrefab()Builds a list of non-null slots and returns a randomly selected prefab from it.
RemoveObjects()Finds and destroys the last container by its stored name, clears the reference, and deletes the EditorPrefs key.

Constants

ConstantValueDescription
CONTAINER_BASE_NAME"__TerrainPrefabPlacer_Container_"Base name prefix for generated containers. A GUID is appended to make each unique.
LAST_CONTAINER_PREFS_KEY"TerrainPrefabPlacer_LastContainer"EditorPrefs key for persisting the last container name across domain reloads.
DEBUG_ENABLEDfalseMaster switch for all non-error debug output. Set to true to enable logging.
DBG_OUT_PREPEND"[TerrainHeightVisualizer/TerrainPrefabPlacer]"Prefix string prepended to all debug log messages from this class.

Tips and Best Practices home

Start coarse, refine later. Use a large grid spacing (200 m or more) for a first pass to preview distribution. Reduce spacing to add density once the placement area and prefab mix look right.

Weight your prefab mix. Fill multiple slots with the same prefab to increase its probability of selection. For example, filling slots 1–7 with trees and slots 8–10 with rocks gives a roughly 70/30 tree-to-rock ratio.

Use the height filter to place by biome. Low-percentile ranges suit vegetation in valleys; high-percentile ranges suit sparse rocks or snow on peaks. Mid-range bands are useful for dense forest placement on slopes.

Generated objects are saved to the scene. Unlike the Terrain Height Spheres tool, these objects persist. Use the Remove Objects button or the Hierarchy to clean up between iterations.

Multiple containers can coexist. Each generation creates a new uniquely named container. This lets you layer different prefab sets at different elevation bands and manage each group independently in the Hierarchy.

Scale variance adds realism. Even a small 10–15% variance breaks up the uniform look of repeated prefabs. Higher values (30%+) work well for rocks and debris; lower values (5–10%) are better for structured objects like fences or props.


FAQ / Troubleshooting home

Q: The Generate Objects button is grayed out.

A: At least one prefab slot must be filled before generation is allowed. Assign a prefab to any slot and the button will become active.

Q: I clicked Generate but nothing appeared in the scene.

A: Ensure at least one active Terrain is present in the Hierarchy. Also check that your Bottom and Top Percentile values are not so close together that no terrain points fall within the band.

Q: Objects are all at the same scale.

A: The Scale Variance % slider is set to 0. Increase it to apply random scale variation.

Q: The objects appear in a visible grid pattern.

A: This can happen with small grid spacing and low scale variance, making the grid-based origin obvious. Increase scale variance, or reduce grid spacing to tighten the random offset radius relative to object size.

Q: Remove Objects says the container was not found.

A: The container may have been renamed or deleted manually in the Hierarchy, or a domain reload cleared the reference. The window clears its internal reference automatically. Locate and delete the container manually from the Hierarchy if it still exists.

Q: I generated objects, closed Unity, and they are gone.

A: You may not have saved the scene before closing. Generated objects are standard scene GameObjects — save the scene after generating to persist them.

Q: Can I use this at runtime?

A: No. Terrain Prefab Placer is an Editor-only tool. The class is in an Editor folder and depends on UnityEditor APIs not available in builds.


Version History home

v1.0.0 — Initial Release


Support and Contact home

For questions, bug reports, or feature requests, please contact us through the Discord channel linked below.

Publisher: BigBuffaloBill

Discord: BigBuffaloBill & Friends Gaming + (bbb-unity-support-forum-public)