API reference
API reference
Select your platform
No SDKs available
No versions available

FinalAction Class

A helper class which invokes a callback on the main thread when this instance is garbage collected.
This can be used to observe the destruction of resources without requiring them to be explicitly disposed.
Prior to Unity 6, this class relies on Context.ExecuteOnMainThread(Action) to invoke its callback on the main thread. In Unity 6+, this dependency is not necessary as Awaitable.MainThreadAsync can be used instead.

Member Functions

Constructor; takes the callback (typically as an inline function) which is to be invoked on the main thread (for example, using Context.ExecuteOnMainThread(Action)) when this FinalAction is destructed.
Parameters
action
The callback to be invoked on the main thread in response to destruction
Cancels the FinalAction.
If this is invoked, then the destruction of this instance will no longer invoke the FinalAction's callback. This is useful in situations where it is no longer necessary to know when the FinalAction is destructed. For example, ValueToClassDecorator<InstanceT, DecorationT> invokes this method when a decoration is manually removed, whereupon the associated FinalAction (which was created to remove the decoration association if the decoration itself is ever destructed) should no longer be called because the association has already been removed.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon