This indeed happens in code. When a character gets hit, the statuses INVISIBLE, SNEAKING and SLEEPING get removed.