[FREE] Vegetation Spawner, procedural tool for the terrain system

Asset store | Documentation

A straightforward but powerful procedural vegetation spawner for the terrain vegetation system. Allows a terrain to be quickly populated with vegetation, without spending days on painstaking manual painting.




6 Likes

Submitted to the asset store, but is pending review, this can take anywhere between 2 to 4 weeks.

Price is a whopping $0, and will be free until it proves to require more time to support than is viable.

2 Likes

Package is now available and up for grabs!

4 Likes

First of all, thank you for the free use.
A problem occurred while trying.
Add Prefab made with Unity Tree Creator
Changes to the parameter can cause a fairly slow or unity to stop.
Is there a solution to this?

And in the case of trees placed with Vegetation Spawner,
light and Post Processing do not seem to be affected.

Sorry, missed your message entirely, wasn’t subscribed to the thread.

Changing the spawn rules of a tree triggers a respawn of it, for a large amount of trees this takes <0.3 seconds. So that is a little slow, but its because a lot of things have to be done. But it ends up being a faster workflow being able to see the effect of a parameter directly.

But it should not freeze Unity, it’s best to always be careful with the distance and spawn chance parameters, because it’s essentially possible to spawn millions of trees, which the terrain rendering can’t handle.

The tool only places vegetation of the terrain, so doesn’t affect rendering. If you’re having issues with rendering, even if you manually paint a tree on the terrain it’s either because of the shader used on the tree, or the way the terrain renders vegetation.


Submitted v1.0.1

Added:

  • Grass items can now be duplicated
  • Exposed seed value in settings tab (global, added to each item’s own seed)

Fixed:

  • Last selected tree item respawning when changing grass spawn rules

Great tool!
Something I was surprised that wasn’t built in so happy to see you’ve built this out.

At first I had some issues, but then realized I was using a non-square terrain so once I made it square everything worked great.

1 Like

First of all thanks for this wonderful asset
just a couple of issues I faced

  • the trees I add are black in color not rendered properly, while placing the same trees using unity terrain tool, the three look fine. They are Il Trees variety pack - unity speed trees
  • also the grass has a default main color and secondary, is their a way to disable this, somehow it overrides the color of the default grass

You’re welcome :wink:

I checked it out, and it appears trees need a specific “lightmap” color, by default this is black, and I’m not setting anything. I assume this is something the tree creator shaders use.

In the VegetationSpawner.cs file, you can insert treeInstance.lightmapColor = Color.white; at line 385, then change a spawning parameter so the trees are forced to respawn with the new color value.

Let me know if that pans out, if so I’ll make the modification permanent.

As for the grass color, the primary/secondary colors are always multiplied over the grass’s texture color. So if your texture is that of a green grass tuft, the colors set for the grass should actually be white in order to fully retain the texture’s color. Using a green color in this case will only make the grass appear darker.

yes this got it working, great and thanks
also couple more things on the grass spawning

  • the white I’m not sure if it is keeping the original grass textures color or adding a white tint to it, also tried setting alpha to zero it does not help, probably having an extra option (checkbox) to just use the original grass texture color will help, (if white does add some tint to the original color)
  • also when having multiple textures of grass if spawn percent of the first texture is 100 then setting the second texture any percentage (eg 20,100) will not spawn it, only the first texture is spawned on the terrain, eg if the first texture is 50 and the second texture is 50 then it spawns both the textures
  • when I have four textures and set 25% to each texture then the first textures does not get spawned
  • also even when setting 100% and spawning the grass there is always space between the meshes/textures, the density is less or does not cover the whole terrain
  • one bug: when changing a value in any field and going to the next object or texture then previously changed value for the previous mesh is visible in the current textures
    I own your grass, water and forest environment all are good assets, probably you could add some more features/rules and supporting all tree types speedtree, mtree etc make this like a indie friendly paid asset around 5 or something or you could even add object spawning make it like a cheaper version 10.
  • Also a discord can help for supports as it is very common these days, also I run a discord to help indie game devs, asset devs help promote their games and asset and network, with around 350 game devs now, you are welcome to join it as an Asset Dev
    https://discord.gg/qfKD939

Helo,

when using HDRP Im finding that the grass prefabs all turn white with no shader at all on them,
can you please help

From what I gathered, grass generally doesn’t work in HDRP, because there is no compatible shader. You can most likely get around this by adding the grass as a tree instead. This way you can use any shader you want.

Thankyou it works when applied as a tree instead!

Although I can’t get many grass bits as much as I’d like since its a tree,
Also the sink amount seems to not have any effect?

That’s kind of a pitfall of the built-in vegetation system, you either can’t have grass other than billboards with the default shader. Or a custom shader, but with a huge performance impact. I’d recommend to check out Nature Renderer, it uses the terrain’s vegetation, but replaces its rendering completely and makes dense grass possible at little performance cost.

For the random rotation and sink to work, the “tree” prefab must have a LOD group (even if it only has one LOD). Another little quirk :wink:

Hi! Can you please help a little bit? Is there is the possibility to display all spawned trees as a prefabs in the inspector? I need to spawn trees and display it at the inspector as a prefabs , so I can interact with it in play mode
Thanks!

The spawned instances of a tree prefab are stored in the terrain’s TerrainData, same as would be when manually painting them. So you could query this to get all instances of a specific prefab like so:

using System.Linq;
using UnityEngine;

public class GetTreeInstancesTest : MonoBehaviour
{
    public Object prefab;
    public Terrain terrain;

    public TreeInstance[] instances;
  
    [ContextMenu("Get instances")]
    public void Refresh()
    {
        instances = GetTreeInstances(terrain, prefab);
    }

    public static TreeInstance[] GetTreeInstances(Terrain terrain, Object prefab)
    {
        if (!prefab || !terrain) return null;

        int prototypeIndex = -1;

        //Get the index of the given prefab
        for (int i = 0; i < terrain.terrainData.treePrototypes.Length; i++)
        {
            if (terrain.terrainData.treePrototypes[i].prefab == prefab) prototypeIndex = i;
        }

        if (prototypeIndex > 0)
        {
            TreeInstance[] instances = terrain.terrainData.treeInstances.Where(x => x.prototypeIndex == prototypeIndex).ToArray();
            Debug.Log(instances.Length + " instances of " + prefab.name + " found");

            return instances;
        }
        else
        {
            Debug.Log("Tree prefab not found in " + terrain.name);
        }

        return null;
    }
}

Thank you! Works beautiful

Hey, just checking this out now. Thanks for making something so useful free!

First impressions, which are somewhat project specific.

  • The UI seems really well designed. Info is displayed and entered in places that make sense for the workflow.

  • Performance seems pretty good. I’ve tried other tools which take minutes to populate a terrain of the size we’re working with (~8km squared), where this does it in ~30 seconds.

  • That said, the auto-respawn when you change some properties is a pain with a terrain that huge. It’d be nice if that could be toggled on/off for when we’re working with terrains too large to work in near-real-time.

  • Something else that’d be great is the ability to spawn GameObjects under a specified parent, in addition to terrain data objects.

Thank you for your feedback :slight_smile:

I’ve added an option under the Settings tab to disable the respawning of trees, when changing a parameter.

I think managing the spawning of GameObjects would be outside of the scope of what I want this tool to achieve. But as an alternative, I’ll add delegate events for when a grass or tree item respawns. This way it’s possible to write custom post processing scripts on top of everything that can check for a specific prefab and do whatever they need.

Example:

using UnityEngine;
using sc.terrain.vegetationspawner;

[ExecuteInEditMode]
public class EventTest : MonoBehaviour
{
    private void OnEnable()
    {
        VegetationSpawner.onTreeRespawn += OnTreeRespawn;
        VegetationSpawner.onGrassRespawn += OnGrassRespawn;
    }

    private void OnDisable()
    {
        VegetationSpawner.onTreeRespawn -= OnTreeRespawn;
        VegetationSpawner.onGrassRespawn -= OnGrassRespawn;
    }

    public void OnTreeRespawn(SpawnerBase.TreePrefab item)
    {
        Debug.Log(item.prefab + " Tree respawned");
    }

    private void OnGrassRespawn(SpawnerBase.GrassPrefab item)
    {
        if(item.type == SpawnerBase.GrassType.Mesh) Debug.Log(item.prefab.name + " grass respawned");
        if(item.type == SpawnerBase.GrassType.Texture) Debug.Log(item.billboard.name + " grass billboard respawned");
    }
}

I’ve added an extension function to the Terrain class, that returns all tree instances for a specific prefab, so it’s possible to get it’s spawnpoints.

using sc.terrain.vegetationspawner;
using UnityEngine;
using Object = UnityEngine.Object;

public class GetTreeSpawnpoints : MonoBehaviour
{
    public Object prefab;
    public Terrain terrain;
    private TreeInstance[] instances;

    private void OnValidate()
    {
        if (!prefab || !terrain) return;

        //Extension function from sc.terrain.vegetationspawner.TerrainSampler class
        instances = terrain.GetTreeInstances(prefab);
    
        Debug.Log(instances.Length + " instances found");
    }

    private void OnDrawGizmos()
    {
        if (instances == null) return;
    
        for (int i = 0; i < instances.Length; i++)
        {
            Gizmos.DrawSphere(instances[i].position, 1f);
        }
    }
}

These two combined would make it possible to spawn GameObjects on trees.

1 Like

Sweet! That makes this super flexible indeed.

Thanks again!

Submitted v1.0.3

Added:

  • Callback delegate for when a grass/tree item respawns (see documentation for example).
  • Terrain extension function for getting a tree instances of a specific prefab.
  • Water level is now visualized in the scene view when the Settings tab is active.
  • Option to disable automatic respawning of trees when a spawn rule is modified.

Changed:

  • Renamed “Opacity threshold” for terrain layer masks to “Minimum strength”, for clarity.
  • Height range maximum value is now based on the height of the largest terrain (instead of being fixed at 2000).
  • Collision detection now works for non-square terrains

Fixed:

  • UI error when switching to a scene with fewer grass items than the last
3 Likes