VariaInstantiate
The VariaInstantiate component picks a random prefab from a list, and instantiates it in the same position as the original component.
The instantiated objects will apply all their varia components too, including more instances of VariaInstantiate, so you can create quite deep nested structures.
Note
You are recommended to only instantiate prefabs, or objects marked with VariaPrototype. Otherwise you run the risk of Varia components being applied twice - once on the original object, and a second time when you instantiate a copy of it.
Depth and recursion
Every time a game object is instantiated inside of another one, a hidden variable called depth
is increased to track how nested the current game object is. depth
can be tested for using conditions.
You can even set up recursive instantiations, where a prefab A creates a prefab B, which creates prefab A again, which repeats until a condition on depth disables further instances. This technique is very powerful, and is described in more detail in the Recursion tutorial.
Warning
Varia has difficulty dealing with direct recursion, i.e. when you set up VariaInstantiate to instantiate a parent of the object the component is on. This can cause an error in some cases. To fix it, either make a "wrapper" prefab that contains the prefab you want to instantiate, or ensure that the object is created with VariaUtils.Instantiate instead of Unity's GameObject.Instantiate.
Settings
Use Weights
By default, each value in the list is equally likely to be picked. If you turn on use weights, then you can set extra values to make some values more or less likely. Each value is picked with frequency proportional to the supplied weight.
Targets
The list of game objects to instantiate. You are recommended to only instantiate prefabs, or objects marked with VariaPrototype.
Then Destroy This
If true, destroys the game object the VariaInstantiate component is on. This can be used to make the instantiation work as a replacement instead.