IsValid

GenericObject.IsValid
Returns true if the object is valid, otherwise false. Objects become invalid once they have despawned or moved out of range. This is equivalent (and quicker) to checking if the BaseAddress of a GenericObject is zero, and as such the LocalPlayer object Me will always be classed as invalid.

Example
// Grab the players current target and wait for it to despawn or go out of range. // Changing/unselecting the target is not the same as it despawning.

UnitObject myTarget = Me.Target;

while (myTarget.IsValid) {	// Waiting for my target to despawn. yield return 500; }

Print("Player's target has despawned.");