The entity sometimes fails due to the dynamic engine
Can you be more specific here ? What does it mean 'the entity fails' ???
Usually, an entity has a number associated. If you check that number you should be right:
if my_entity > 0 then ;entity exists else ;entity does not exist endif
Note:
If you have a type element which has a field that you use as an entity pointer, and you want to delete that element type, then you should free the entity first, and then delete the type:
FreeEntity mytype\entity ;first release the entity delete mytype ;then delete the type element