The CreatesEvent property is a property which controls whether a Screen or Entity will raise an event whenever a given variable is set. For example, you may want to update a health bar object any time a Player’s CurrentHealth variable is set.

How to use CreatesVariable

For this tutorial I’ll use a Width variable that we’ll create:

  1. Expand your Entity and find the “Variables” tree item
  2. Right-click on Variables
  3. Select “Add Variable”
  4. Select “Create a new variable”
  5. Verify the type is “float”
  6. Enter the name “Width”
  7. Click OK

Now that the Width variable has been created, let’s make an event for whenever the variable is set. You can do this one of two ways:

Drag Drop

The easiest way to do this is to drag+drop the variable onto the “Events” tree node

  1. Push and hold the left mouse button over the “Width” variable
  2. Move the moue down to the Events tree item in the same Entity
  3. Release the mouse buttonCreatesEventDragDrop.png

Setting CreatesEvent in the Variable’s properties

Instead of drag+dropping, you can manually set up the event through Glue as follows:

  1. Create a variable. In this tutorial I’ll use a new float variable called “Width”
  2. Select the newly-created variable.
  3. Set the CreatesVariable variable to true:CreatesEvent.png

Once a variable has its CreatesEvent set to true, you will need to tell Glue to create a function that will be called when this variable is set (the drag+drop method shown above automatically does this for you). To do this:

  1. Right-click on Events
  2. Select Add Event
  3. Select to Expose an existing event
  4. Select the event for your variable. For example, if your variable is called “Width” then select the AfterWidthSet event.AfterWidthSetEvent.PNG
  5. Click OK

Editing the Event

If this is the first event you have created for the selected Screen/Entity, Glue may notify you that it has created a new file. The file will be called


You can now code the contents of the event in Glue, or in Visual Studio.

To edit the code in Glue, select the event in Glue and a code window will appear:EventCodeWindow.png

To edit the code in Visual Studio, open your project, and navigate to the Screen or Entity code file in Visual Studio. Expand the item and you will see the Event.cs file:EventInVisualStudio.png

Viewing events in real time

GlueView has a built-in code parser/interpreter. Therefore, if you write event code in Glue or Visual Studio, GlueView will automatically parse and apply the event code in real time.

To see this, first we’ll create an AxisAlignedRectangle in Glue:

  1. Select your Entity (in this case UiFrame)
  2. Right-click on Objects and select “Add Object”
  3. Select “FlatRedBall or Custom Type”
  4. Select “AxisAlignedRectangle” in the list
  5. Click OK

If you open GlueView you will see the AxisAlignedRectangle:DefaultRectangleInGlueView.png

Next we’ll add some code to modify the AxisAlignedRectangle when Width is set. To do this:

  1. Select the AfterWidthSet event in Glue, or open up Visual Studio and navigate to your Entity’s Event.cs file (which in this case would be UiFrame.Event.cs)
  2. Add the following code:
    this.AxisAlignedRectangleInstance.Width = this.Width;
  3. Select the “Width” variable in the Entity
  4. Set the value to 128
  5. Notice that GlueView automatically updates the size of the rectangle according to the code you have written in the event:WidthChangeInGlueView.png

Using Events in Custom Code – Advanced

Note that the steps above are all that is necessary to create an event and use it in custom code. However, since events created by Glue are actually events ( the C# keyword ), you can use the created events in your custom code inside the object that defines the event, or you can += the event on any instance.

Once a variable has CreatesEvent set to true, the class containing the variable contains two events – one which is called before the variable is set and one after the variable is set. The names of the events are:

  • Before[VARIABLE NAME]Set – for example BeforeScaleXSet
  • After[Variable Name]Set – for example AfterScaleXSet

If you expose the event, then you simply have to open the ELEMENTNAME.Event.cs file to code right in the event. Or you can += it in custom code.

In custom code simply += a method as shown in the following:

private void CustomInitialize()
    this.AfterWidthSet += new EventHandler(CustomWidthHandler);

void CustomWidthHandler(object sender, EventArgs args)
    // Do whatever you want whenever Width is set