Bind Updates Controls
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 Bind<T>
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 IBindController
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:
UpdateAllBinds()
updates all related bindings—both those where the object acts as a bind source and those where it serves as a target.UpdateBind(string memberPath)
updates only those bindings that involve the specified member path (field or property), whether the object acts as a source, a target, or both.PauseAllBinds()
pauses all bindings related to the object, be it source or target of the bindings.ResumeAllBinds()
resumes previously paused bindings.PauseBind(string memberPath)
pauses only the bindings related to object and to specified member (field or property) path.ResumeBind(string memberPath)
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.
To be able to call these methods from within the same object, call them preceded with this
operator. For example: this.UpdateAllBinds()
To better illustrate this, the following example shows a couple of objects in different configurations.
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
}
public class CarController : MonoBehaviour
{
public float[] gears;
public float maxPower;
// ... Other properties related to car controller
}
Now CarController can bind its fields from CarEngineData:

In this case, the fields will update their values (CarController's gears
and maxPower
) only when RecomputeData()
on CarEngineData will be called.
Last updated
Was this helpful?