Very simple actually. Just call HEU_HoudiniAsset:: DuplicateAsset() which should return a new GameObject that is a duplicate of the asset. This is what the Duplicate Asset button does.
Here is an example of duplicating a selected asset via C#:
[MenuItem("Test/TestDuplicate")]
public static void TestDuplicate()
{
GameObject rootGO = Selection.activeGameObject;
if(rootGO == null)
{
Debug.LogWarning("Nothing selected. You need to select an asset!");
return;
}
// The selected gameobject is the asset's root gameobject.
// Get the root component (HEU_HoudiniAssetRoot) which will allow us to get the asset component (HEU_HoudiniAsset) itself.
HoudiniEngineUnity.HEU_HoudiniAssetRoot root = rootGO.GetComponent<HoudiniEngineUnity.HEU_HoudiniAssetRoot>();
if (root != null)
{
HoudiniEngineUnity.HEU_HoudiniAsset asset = root._houdiniAsset;
// This will return a duplicated asset as a gameobject
asset.DuplicateAsset();
}
}
Note that I just fixed a regression with the DuplicateAsset function that will be in tomorrow's build (H16.5.502). The duplicated asset wasn't cooking.The reasons for the explicit duplicate method as opposed to using Unity's built-in duplicate or copy/paste mechanism are that aside from the lack of a consistent way to capture copy/paste or duplicate events in the Unity, we also need to create a duplicate asset in the background Houdini session that connects to the Unity's duplicate instance, and we're using ScriptableObjects internally in the asset, which do not get duplicated via the built-in way but rather just have their references copied.