Referencing destroyed objects

Hello you can check if a Actor is marked for destruction with the following methods.



[AActor::IsPendingKillPending](https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AActor/IsPendingKillPending/index.html)
[UObjectBaseUtility::IsPendingKill](https://docs.unrealengine.com/latest/INT/API/Runtime/CoreUObject/UObject/UObjectBaseUtility/IsPendingKill/index.html)
[UObjectBase::IsValidLowLevel](https://docs.unrealengine.com/latest/INT/API/Runtime/CoreUObject/UObject/UObjectBase/IsValidLowLevel/index.html)


Also before you use any new pointer you check it to see if its valid or not.


if ((customEnemy) && customEnemy->getHealth() <= 0) // If valid and less then or equal to 0
{
      // e.g:
      customEnemy->IsPendingKillPending(); // true if this actor has begun destruction, or if this actor has been destroyed already. 
      customEnemy->IsPendingKill(); // Checks the RF_PendingKill flag to see if it is dead but memory still valid
      customEnemy->IsValidLowLevel(); // true if this appears to be a valid object
}

Hope it helps.

1 Like