Calling hdaModule functions in Unity

   3293   3   0
User Avatar
Member
85 posts
Joined: Aug. 2010
Offline
Hi there

So I have an HDA with a python function call attached to a button paramater as a callback. In Unity this button works if I hit teh button in the GUI
Is there a way to call the same function via the API in Unity or a nice way of pushing the button programmaticlly?

I could not find any mention of buttons in HEU_ParameterUtility

many thanks
Sam
Sam Swift-Glasman
Art Director
Five AI
User Avatar
Member
571 posts
Joined: May 2017
Offline
You're correct, the HEU_ParameterUtility doesn't have an example for buttons. But button parms are integers that simply need to have their value toggled between 0 and 1. Here is a code example of how to do so:

[MenuItem("HEngineiActions/DoExportButton", false, 0)]
public static void DoExportButton()
{
	GameObject[] selectedObjects = Selection.gameObjects;
	if (selectedObjects == null || selectedObjects.Length == 0)
	{
		return;
	}

	GameObject go = selectedObjects[0];

	HEU_HoudiniAssetRoot root = go.GetComponent<HEU_HoudiniAssetRoot>();
	if (root == null || root._houdiniAsset == null)
	{
		return;
	}

	HEU_HoudiniAsset asset = root._houdiniAsset;

	// Button name is "reload". Its node must be marked as editable.
	HEU_ParameterData paramData = asset.Parameters.GetParameter("reload");
	if (paramData != null)
	{
		// Triggering button and cooking
		// Buttons are integer values that need to switch between 0 and 1 in
		// order to trigger them.
		paramData._intValues[0] = paramData._intValues[0] == 0 ? 1 : 0;
		asset.RequestCook(false, true, true, true);
	}
}
Edited by seelan - Sept. 23, 2019 08:42:13
User Avatar
Member
85 posts
Joined: Aug. 2010
Offline
Excellent thanks Seelan!

We'll give that a go
Sam Swift-Glasman
Art Director
Five AI
User Avatar
Member
6 posts
Joined: Jan. 2019
Offline
Hello!

Seelan, thanks for your help. I've tried what you suggested, toggle the int value of the button but can't seem to get it to work.
I've made the node editable, as I saw something on another post that suggested this.

Are there any other ways of triggering the button / just running the hdaModule function within Unity?

Many thanks,

Will
  • Quick Links