Fix entity cast crash