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.
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.
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.
Package is now available and up for grabs!
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:
Fixed:
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.
First of all thanks for this wonderful asset
just a couple of issues I faced
You’re welcome
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
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
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
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.
Sweet! That makes this super flexible indeed.
Thanks again!
Submitted v1.0.3
Added:
Changed:
Fixed: