Runtime Prefab Spawner Pro

Runtime Prefab Spawner

The Runtime Prefab Spawner component is designed to instantiate prefabs related to the trees or objects in Vegetation Studio. It allows you to assign a prefab to a Vegetation Item. When the item is within range of the camera an instance of the prefab is created at the exact location of the item. This item will be removed automatically when the item is out of range again.

The use case for this could be to add effects like falling leaves, insects near flowers,  sounds from the old tree, harvesting logic etc. The prefabs can have any scripts attached.

The rules set up in the prefab spawner is saved in the vegetation package.

This approach allows you to add special functionality to large amounts of vegetation items with no extra overhead of culling and processing the effect gameobjects in the hierarchy.

You add it to the GameObject with the VegetationSystem component and configure.

In this example video we added a prefab with a falling leaves particle effect to one of the tree models. When any tree of this type gets within range it will instantiate a copy of the effect with the same position as the tree. When it is out of range it is removed automatically. This will allow for effects on huge amounts of trees or plants with no overhead of culling and gameobject hierarchy handling.

Image showing the falling leaves.

Select biome/vegetation package

Select what vegetation package you want to edit rules for.

Select vegetation item

Select the vegetation item you want to add or edit rules for.

Add run-time prefab rule

Click this to add a rule to the selected item. A item can have more than one rule.

Edit rule settings

These are the spawing rules for each added prefab. Adjust to get the frequency and position you want.

Spawn frequency

Spawn frequency is the chance of a prefab being spawned on a vegetation instance. 1 = 100% of instances.

Scale

This controls the scale of the prefabs. This overrides any scale set in the transform of the prefab from before.

Add vegetation item scale

Trees and rocks have a random scale set on the vegetation item. select this to have the prefab scale with the vegetation item instance.

Rotation

Rotation in localspace of the vegetation item.

Offset

Offset in localspace of the vegetation item

Prefab Layer

Here you can set the layer the instantiated prefab will be added to.

Seed

Random seed for selection of what instances that get a prefab spawned.

Use pooling system

By default prefabs will be using the built in pooling system. Prefabs are disabled and enabled before used again. Uncheck this if the prefab can not be pooled.

Distance factor

This sets the distance from camera where the prefab will be created/removed

Remove run-time prefab rule

Click this to remove the prefab rule.