Behavior.OnAdded() Method
Definition
Namespace: Brine2D.ECS
Called once when the behavior is added to an entity. Use this to validate required components and cache references.
Example
C#
protected override void OnAdded()
{
_transform = Entity.GetRequiredComponent<TransformComponent>();
_velocity = Entity.GetComponent<VelocityComponent>();
}
Remarks
OnInitialize() may not have been called yet when this method runs.
AddBehavior<T>() executes immediately, while OnInitialize()
is deferred until the next Brine2D.ECS.EntityWorld.Flush /
Brine2D.ECS.EntityWorld.Update\(Brine2D\.Core\.GameTime\) call. Do not rely on state that OnInitialize
sets up from inside this method; use Brine2D.ECS.Entity.GetComponent<> and
component data instead, which are available immediately after being added.