This is pretty much one of the most current theories on how dreams work and why we have them. So, while are are asleep our brain is making connections for events that happened in the day However, you still feel emotions, these emotions are almost spontaneous, but to help your mind deal with intense emotions, it pieces events from your life in no necessary order into a narrative. It doesn't have to make sense as long as it incites the right feelings. REM sleep is exciting since it is kind of like a simulation for your mind. Your mind tests out various possibilities. Now it's not perfect, and since the part of your brain involved in figuring out what will happen next, piecing things together chronologically and the like, is inactive during this phase. These dreams are vivid and easy to remember.
That is however, in REM sleep. You CAN dream in non-REM sleep. However, these dreams are just recaps of things you had been doing/thinking about a lot that day. Say if you had just been to Walmart you might dream about shopping for some food or something. This is just your brain connecting ideas that will help you in your waking life, which are usually boring. These dreams are bland, and forgettable. These dreams are ones that would be considered "boring". Dreams like going to the kitchen and eating a bowl of cereal would be like this.
Any questions, leave them in a response, if you have a more personal question PM me.
Ecchi first, ask questions never.