Breaking Bad Habits...eating in the middle of the night

I have had a bad habit for as long as I can remember. I wake up randomly in the middle of the night and go into the kitchen and eat. I am not hungry, and usually only barely aware of what I am doing. Its like I'm sleep-eating. I am awake enough to know what I am doing (most of the time) but not strong enough to stop. I have tried in the past to associate when I do this with events in my daily life, like did I exercise hard that day? drink too much alcohol that night? have a stressful day? I have not been able to find a correlation. It seems to come and go in phases. I think it may just be a bad habit? Maybe I am missing nutrients in my diet and my body eats to satisfy? I usually eat some leftovers or a snack bar, anything that is easy to shove in my mouth. But it adds up to a full meal of calories, enough to keep me from loosing weight. Has anyone else had this problem? How did you deal with it? Is there a reason I am doing this? How can I stop?