Erectile dysfunction usually develops over time and is a gradual loss of function. If ED were to occur unexpectedly, this is more likely due to a side effect of a medication or a psychological issue. See a doctor if the condition persists to get treated.