Houdini Engine for Unity (v2 beta)
 All Files Pages
Unity Scripts

Existing Unity Component-derived scripts can be attached to the asset's output GameObjects via custom attributes. Additionally, a function on the script can be invoked with an optional string argument. This is done after the asset has been fully cooked and all of its outputs generated. Note that the specified Component will only be added if the GameObject does not already have it. The function will be invoked on every recook though.

The attribute must be a detail attribute of string type, with name unity_script. It must have the following format:

script_component_name:function_name:argument

The script_component_name should be the name of the Component-derived class in Unity.

The function_name should be the name of a function within the Component, and is optional. If invoking a function, the class must also have the **[ExecuteInEditMode]** tag.

The argument could be any string-value and is optional. This allows to pack and send any values that can be parsed by the receiver.

For example, if you have a script called Test.cs such as the following:

[ExecuteInEditMode]
public class Test : MonoBehaviour
{
public string _msg;
void HDACallbackWithMsg(string msg)
{
Debug.Log("Callback with msg: " msg);
}
void HDACallbackNoMsg()
{
Debug.Log("Callback with no msg");
}
}

Then, the custom attribute could be one of the following, depending on the callback:

Only attach the script. No callback.

Test

Attach script and do callback, no argument:

Test:HDACallbackNoMsg

Attach script, do callback with argument:

Test:HDACallbackWithMsg:hey this is a message

Multiple scripts can be attached by adding a semi-colon between each script name:

ScriptA:FunctionA:MsgA;ScriptB:FunctionB:MsgB;ScriptC:FunctionC:MsgC

To see a working example, load the HoudiniEngineUnity/Examples/HEU_Example_Unity_Script.hda in Unity. It will attach HoudiniEngineUnity/Scripts/Examples/HEU_ScriptCallbackExample.cs to the asset's output GameObject, and invoke the function with argument containing the message "Hello".