The Sims 2EditIn The Sims 2, Sims can have nightmares if players haven't been taking care of them. They will have nightmares if they go to sleep with very low motives. They also have a much higher chance of having a nightmare if they passed out from exhaustion and the player made them wake up and go to bed. They can also have nightmares if they are in an aspiration desperation or are in the red. For example, if your Sim just witnessed a death or just lost their job, they will more than likely have a nightmare.
The Sims 3Edit
In The Sims 3, if Generations is installed, it is also possible for child and teen Sims to have nightmares. If the player clicks on the sleeping child or teen, it will pop up an option of dreaming about a certain topic. Occasionally, when the player does this, a message will be given, informing that the dream has turned into a nightmare. When the Sim wakes up, they will gain a negative moodlet from the experience.
The Sims 4 Edit
Only toddlers have nightmares in The Sims 4, although children can wake up with an Uncomfortable moodlet due to a monster under a bed, which only Children can see. The player may wait this out, although if you want it to become less likely for a Child to do this again in the future, alternatively, you can make an adult "Spray the Monster Under The Bed". Unlike toddlers's nightmares, all sleeping Children on the lot will wake up as well as the Child who discovered the monster.