I had a similar realization, but it was a more generalized version of what you described. Unhappiness is what happens when expectations or desires don't match up with reality; if you want to be happy, learn to be content with the moment and what exists right in front of you right now.
On the other hand, one needs to dream, and hope--and that's what we should do. But leave goals and hopes for the future only, and don't hold on to failures, dwell on the past, or what could have been, or what is (whatever current reality you're discontent with).