User Guide > Rigging > Master Controller > Creating Widgets

Creating Master Controller Widgets


The UI script linked to a Master Controller node is called when the Master Controller node is selected and the user uses the Show Control command to display its controls in the camera view, which calls the onShowControl method of the Controller object of the node. Hence, to make the Master Controller node display a widget, you must define its widget in a function that overrides this method.

The following example overrides a Master Controller's onShowControl method with a function that creates a basic slider widget. Simply copy and paste it to your UI script to test its effect.

// When Show Controls is called from the Harmony UI, create a script widget // and register it to the main Controller. Controller.onShowControl = function() { // Initialize the array of widgets Controller.controls = []; // Add a slider widget. Controller.controls.push(new SliderWidget()); }

Similarly, you can handle the case where the control is hidden using the onHideControl method.

// Called when the user hides the Master Controller node controls Controller.onHideControl = function() { MessageLog.trace("Slider hidden."); }
NOTE: When the control is hidden, it is destroyed and the attributes that were set by the user when they manipulated it are not preserved. This occurs regardless of whether or not the onHideControl method is overridden. Hence, there is no need to script the destruction of the widget.

It is possible to create a Master Controller with several widgets. For example, you can combine a TranslationXWidget and TranslationYWidget to make a 2D Translation widget by creating them as elements of the same Controller.controls array.

// Create a TranslationX and TranslationY widget in the same Master Controller. Controller.onShowControl = function() { // Initialize the array of widgets Controller.controls = []; // Add the TranslationX and TranslationY widgets Controller.controls.push(new TranslationXWidget()); Controller.controls.push(new TranslationYWidget()); }

Save your script, then refer to the following topic to display and use the Master Controller's widget.

NOTE: To learn about the different widgets available for the Master Controller, refer to the Master Controller Node section of the Harmony scripting reference–see Scripting Reference.