# Bind Updates Controls

{% hint style="info" %}
Available from version 2.4.0
{% endhint %}

By default the system updates each bound field according to its specified update points, which can be configured in Bind Menu. Sometimes however,  it is necessary to manually control when to update the bindings and which one. In previous versions this could be accomplished either by manually adding <mark style="color:yellow;">`Bind<T>`</mark> fields and work with them in code or by hooking to a `UnityEvent` and let it trigger an update of bindings. Starting from version 2.4.0 there is a third way to accomplish this, which is code-based and gives easier control over bindings.

### Usage

To be able to control the bindings of an object, the object needs to implement <mark style="color:yellow;">`IBindController`</mark> interface. The interface per se doesn't require any method to be implemented, it just serves only as a class marker. Once the object implements this interface, a number of extension methods become available:

* <mark style="color:yellow;">`UpdateAllBinds()`</mark><i class="fa-arrow-right">:arrow-right:</i> updates all related bindings—both those where the object acts as a bind source and those where it serves as a target.
* <mark style="color:yellow;">`UpdateBind(string memberPath)`</mark><i class="fa-arrow-right">:arrow-right:</i> updates only those bindings that involve the specified member path (field or property), whether the object acts as a source, a target, or both.
* <mark style="color:yellow;">`PauseAllBinds()`</mark><i class="fa-arrow-right">:arrow-right:</i> pauses all bindings related to the object, be it source or target of the bindings.
* <mark style="color:yellow;">`ResumeAllBinds()`</mark><i class="fa-arrow-right">:arrow-right:</i> resumes previously paused bindings.
* <mark style="color:yellow;">`PauseBind(string memberPath)`</mark><i class="fa-arrow-right">:arrow-right:</i> pauses only the bindings related to object and to specified member (field or property) path.
* <mark style="color:yellow;">`ResumeBind(string memberPath)`</mark><i class="fa-arrow-right">:arrow-right:</i> resumes previously paused bindings related to object and specified (field or property) path.

The important thing to remember is that (for now) there is no distinction between the object acting as source or target for bindings. This removes the micro-management from the equation and makes updating easier to accomplish.

{% hint style="warning" %}
To be able to call these methods from within the same object, call them preceded with **`this`** operator. For example: `this.UpdateAllBinds()`
{% endhint %}

To better illustrate this, the following example shows a couple of objects in different configurations.&#x20;

```csharp
public class CarEngineData : ScriptableObject, IBindController
{
    public float load;
    public float engineMaxPower;
    public float[] gearsRatio;

    public void RecomputeData()
    {
        // Heavy computation logic to recalculate car data

        this.UpdateAllBinds();  // <-- NOTE: 'this' operator is mandatory!
    }
    
    //... Other methods and properties related to car data
}
```

```csharp
public class CarController : MonoBehaviour
{
    public float[] gears;
    public float maxPower;
    // ... Other properties related to car controller
}
```

Now CarController can bind its fields from CarEngineData:

<div align="left"><figure><img src="https://3780647524-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnpeBTRzgLGSQUWVhwqoi%2Fuploads%2FTGlKtonyll4mm7zkMwhO%2Fimage.png?alt=media&#x26;token=37d7eb43-aa5d-44f9-b70e-95b434ee67ea" alt="" width="563"><figcaption></figcaption></figure></div>

In this case, the fields will update their values (CarController's `gears` and `maxPower`) only when `RecomputeData()` on CarEngineData will be called.&#x20;
