ComponentChanged.OldComponent_T_().md

February 25, 2024 ยท View on GitHub

Friflo.Engine.ECS

Friflo.Engine.ECS.ComponentChanged

ComponentChanged.OldComponent() Method

Returns the old component value before executing Update or Remove component.
Note: See Remarks for restrictions.

public T OldComponent<T>()
    where T : struct, Friflo.Engine.ECS.IComponent, System.ValueType, System.ValueType;

Type parameters

T

The component type of the changed component.

Returns

T

Exceptions

System.InvalidOperationException
In case the Action was Add component.

System.ArgumentException
In case the component is accessed with the wrong generic type.

Remarks

Note: The OldComponent<T>() return value is only valid within the event handler call.
ComponentChanged may return an invalid value when calling it outside the event handler scope.
Instead store the value returned by OldComponent<T>() within the handler when using it after the event handler returns.
Reason: For performance there is only one field per component type storing the old component value.