πŸ”ΉProperty Bindings

This section explains how bindable properties link data in CAS.

Overview

Property Bindings is a system for binding values in the editor. CAS uses it to link gameplay code (e.g., character controllers) with the animation system (Procedural Animation and Layered Blending).

Example of a property binding.

Editor

When pressing the "+" icon, a property binding will try to search for potential bindable public fields, properties, and methods. Here is what happens on the low level:

  1. Get a GameObject context β€” it is typically a player prefab reference, provided by the interface.

  2. Iterate over all components and look for public fields, properties, and methods that return the desired type.

  3. Create a dropdown menu with potential bindables.

  4. Once a bindable is selected, the binding's path and component type will be updated.

To get a GameObject context, Property Bindings rely on the IBindableContext interface:

Initialization

Property Bindings needs to be manually built, which typically happens when the game starts:

circle-check

In some cases, it is important to create a safe copy of a property:

This can be useful when one binding is used with different instances. For example, if we bind a player-controlled offset to the animation system, we must ensure that each instance of our player has separate control over that bound property.

Getting a value

BindableProperty.GetValue() is used to return the current value of a bound property.

circle-check

BindableProperty.SetDefaultValue(T value) is used to update the default value of the property. The default value is only used when:

  • A property wasn't initialized successfully.

  • One of the references is null.

Updating context

When a binding is built during initialization, on the low level, it creates a function that takes a MonoBehaviour component as a parameter. It is possible to change the context for a property at runtime:

circle-check

Last updated