Behaviors
Introduction
By default, a new Gum project has no behaviors. The most common way behaviors enter a project is automatically: adding Forms controls (Button, TextBox, Slider, and so on) adds their matching behaviors for you - see Default Behaviors below.
Creating or editing behaviors yourself is an advanced, rarely-needed scenario. The vast majority of projects only ever use the behaviors that Forms controls bring in automatically.
A behavior defines requirements that are reusable across multiple components: required categories and states, required instances, and optionally Behavior Properties - design-time properties that surface in a Behavior category in the Variables tab and connect to properties on the runtime Forms control (such as TextBox's TextWrapping or Slider's Minimum/Maximum). Behavior Properties are covered in Behavior Properties below. If a component uses a behavior, then the component is forced to include categories and instances according to the behavior definition.
Common behavior usage falls into one of two categories:
Behaviors for built-in controls such as Button and TextBox exist to make customization for these types of controls easier.
New behaviors can be created to match the syntax of controls defined in your game project. This is considered an advanced scenario and is rarely used.
Default Behaviors
If your project has added forms components, then it should contain a set of default behaviors matching the forms control types.

These behaviors are used by the Gum runtime to decide whether a component should have the behavior of a particular control type.
For example, a component with a NineSlice background will not respond to cursor hover events by default. However, if the ButtonBehavior is added to this component, then the component is required to contain certain states which are used at runtime to react to hover, push, and disable states.
In other words, behaviors answer the question "How can I give default forms behavior to my component" by providing a required set of states, instances.
Default Control Behaviors
As mentioned above, if you have added forms controls to your project, then you should have a set of components which already implement the default behaviors defined below.
For example, we can look at the ButtonStandard component which implements ButtonBehavior.

By using the ButtonBehavior, the ButtonStandard will automatically be associated with the Button type at runtime.
Furthermore, the ButtonStandard component is required to include the category and states defined by ButtonBehavior.
Notice the categories and states defined by ButtonBehavior:

These automatically-added states are empty - they do nothing by default. For information on working with states, see the States page.
Gum prevents the removal or renaming of any of these states from ButtonStandard since they are required by ButtonBehavior.

Adding Behaviors to Components
If you are creating a new component which should be used as a standard forms type, such as creating a new Button style, then you will need to add a behavior to the component. By adding a new behavior, Gum will add required states automatically and will display errors if any behavior requirements are missing.
For example, consider the creation of a new component which will have button behavior (responding visually to hover and push, enabled/disabled support, and click events).
To add the ButtonBehavior to a component:
Select your component
Click the Behaviors tab
Click the Edit button
Check the desired behavior (
ButtonBehavior)Click OK to apply the selected behavior
Gum automatically creates the ButtonCategory and required states. Keep in mind that these states are empty - it is up to you to select the states and customize your component appropriately.

Behavior Instance Requirements
Some behaviors have instance requirements too. For example, the TextBoxBehavior has two required instances:
TextInstance which uses a base type of Text
CaretInstance which can be of any type

TextBoxBehavior has required instancesIf this behavior is used in a component, Gum displays errors indicating that instances are missing.

You need to add instances to your component to satisfy these errors or else the component may not function properly at runtime, and may even cause runtime crashes.
Behavior Properties
Beyond categories, states, and instances, a behavior can declare Behavior Properties, which are design-time properties that appear in a Behavior category in the Variables tab and flow through to the matching property on the runtime Forms control. For example, TextBoxBehavior declares properties matching TextBox's TextWrapping, AcceptsReturn, IsReadOnly, and MaxLength; SliderBehavior declares properties matching Slider's Minimum and Maximum, and ScrollBarBehavior declares Orientation. Setting one of these in the Variables tab sets the corresponding property on the control when your game runs.
Some Behavior Properties also drive a visual state automatically, so you get a design-time preview even though Forms controls don't run inside the tool. For example, setting TextWrapping in the Behavior category updates the component's visual line-mode state immediately. See Behavior-Driven References for how this works.
ScrollBar Orientation
A ScrollBar instance has an Orientation setting in the Behavior category. It defaults to Vertical. Set it to Horizontal to place the buttons left and right of the track, both in the tool and in your game. The instance does not list the scroll bar's orientation state, so set Orientation instead.
Custom Behaviors
You can add your own Behavior Properties and behavior-driven references to a custom behavior you create, but this is an advanced, rarely-needed scenario. See Behavior Properties on Custom Behaviors for a brief overview.
Last updated
Was this helpful?

