Poisson Disk Sampler Usage Guide



Want to fill a region with rocks, trees, or other foliage? Placing each prefab by hand can be a nightmare, and creating a script to place them randomly can create unnatural results. The Poisson Disk Sampler, available on the Unity Asset Store, can solve that!

How does it work? It's simple! Using Poisson Disk Sampling, a minimum distance between each prefab can be specified, creating much more aesthetically pleasing results. Just pick a region to generate in and let the Poisson Disk Sampler take care of the rest!

Basic Usage

Using the Poisson Disk Sampler is simple!

1) Create a new game object and add the Poisson Disk Sampler component to it.

2) Use the bounds property to specify the region you would like to generate in. It will be indicated by a green outline in the viewport (if you don't see a green outline, make sure that Gizmos are enabled).

3) Assign a prefab to the spawn prefabs list. You can optionally assign multiple prefabs and assign custom spawn weights.



4) Press "Generate" and you should see your region be automatically filled with your prefab!

5) (optional) Enable the "Snap to Terrain" option. This will cause each prefab to check for terrain below it (using a raycast) and snap to the surface. Useful for generating on rough or hilly terrain!



Advanced Usage

If you have custom data that you want to randomize for each prefab that's spawned, you can do that with spawn events!

1) Create a new script to listen to the spawn event

2) Add a public method with return type void that takes in a GameObject as its input. This game object represents the newly spawned prefab.


3) Go back to the PoissonDiskSampler component and click the plus to add a spawn event. Assign the object with the new script you just created and choose the method you created (Make sure you select the method listed under the "Dynamic Game Object" heading).



4) Now that everything's hooked up, add whatever custom code you'd like to the spawn event listener! In this example, we will use it to randomize the height of each prefab.




For feature requests, bug reports, or support, send a DM to Nickmiste#3242 on discord, or email me at nickmiste@gmail.com

Comments