I've discovered that you have to look at your life as moments in time, especially as a software engineer. You will build something awesome, and you will be proud of it, and all will be right with the world. And then, the company you built it for will discontinue the project or die altogether and you're left with nothing.
The key to staying sane is remembering those moments when your accomplishment was there in front of all those people and you were excited and showing it off to your friends and family.
Chances are that almost everything you ever made will be obsolete in a few years, and probably long forgotten in 20 -- unlike, say, a civil engineer who's roads will be around for the foreseeable future.