Houdini Engine for Unity
 All Files Pages
Instancing

The plug-in allows to instance generated or existing geometry easily.

The following shows a cube in Unity being instanced:

Unity_Instancing_PackedPrimFull.png

Three types of instancing are supported:


Packed Primitives

Packed primitives are essentially primitives that live inside of SOPs and contain one or more primitives with their own transforms. Packed primitives can contain other packed primitives allowing to have a full transform hierarchy completely inside of SOPs. The benefit of using packed primitives is that only one copy of the geometry is stored in memory for all the instances.

In Unity, a packed primitive output (GameObject) is instantiated such that its mesh data is shared, rather than copied, for each instance. Also, GPU Instancing is automatically enabled on the generated Materials to allow for batched rendering.

A simple way to use this method is to use a Copy To Points SOP with the Pack and Instance option enabled. You also have the option to use Pack Geometry Before Merging on Inputs.


Object Instancers

Instancers can also be created using the instance Object node. While this is a valid instancing method, it is recommended to use Packed Primitives for instancing generated output.

Unity_ObjectInstancingUI.png

The above shows input field for an object instancer. If multiple objects are specified, they will be treated as a single object and instanced.


Attibute Instancers

Existing Unity Prefabs can also be instanced via the special unity_instance attribute. This point or detail attribute should be string-type, and contain the path in Unity project of the asset to instance. Path should be relative to the project Assets folder (eg. "Assets/Prefabs/Hero.prefab").


Overriding Instance Inputs

You can expose the Object Path Input Parameter allowing to override the geometry being instanced via Inputs.

Unity_PackedPrimInstancingUI.png

For attribute instancers, if more than 1 GameObject is added to the input list, they will be randomly used for instancing. This provides automatic variety for instances.


Instance Names

The default convention for the names of the gameobjects for instances is: geoname_Instanceindex. This would produce something like "Cube_Instance2" for the second instance of geo node named "Cube". To override this behaviour, a string attribute named instance_prefix can be used to set the prefix part of the name. In the example, this would replace the geo node name "Cube" with the value in the instance_prefix attribute. The attribute must be Detail or Point owned.

Single instance prefix using Detail attributes

When using a Detail attribute to set the instance prefix, all instances will have the same prefix.

Unity_Instance_Names_DetailAttr.png

Multiple instance prefixes using Point attributes

Using Point attribute, each instance name prefix can be set individually.

Unity_Instance_Names_PointAttr.png