Checking when a parent object is destroyed...

This is an odd question, but here it goes. When an object’s parent is destroyed by an external script, is there a way to do something in a script attached to the object right before it is destroyed? For example: script-A is attached to an object that is the child of yet another object. A separate script goes to destroy that parent object. Script A detects this and does something before it is destroyed. Can this be done?

Before the parent gets destroyed the script which destroys it had to Broadcastmessage(BroadcasMessage actives all functions in parent and its childs) and so activate a function in the script of the child.

This way this function gets activated before the parent gets destroyed.

Example:

TheParent.BroadcastMessage("Dying");
Destroy(TheParent);

Hope this works.