Good topic! I notice the exact same thing whenever I lose track of my weight loss. If my head's not in the right place, the rest just doesn't happen.
So, how do I mentally stick to my journey? I think I can categorize it into a few areas:
Acceptance of my current weight. I started gaining weight when I got a sedentary job, and after a few months, I put on 30 pounds! Having to buy larger pants was very depressing, but learning how to love and accept myself was the key to realize that I have the power to change this no matter my age or job type. I started researching weight loss forums, and this community has been so helpful with my own personal acceptance. Accepting myself at this weight helped me realize that if I can gain it, I can lose it!!
Consistent food choices & Listening to cravings. I have been prepping my meals (breakfast, lunch, dinner, & snacks) for the past year. My husband recently got on board with this, and it saves us time and energy during the week. More so, it helps us make healthier food choices. It may sound boring, but we basically eat the same thing during the week anyway. Food consistency has been so helpful in training my body to crave healthier food - salads, veggie sticks, fruit slices, lean meats - and needing smaller portions to feel full. Since I know I'm consistent with food during the week, when my body is craving salt or sugar (lately more salt than sugar), I can more easily give into that craving and not overdo it.
The long-term perspective. I think about how quickly switching to a sedentary job caused me to put on weight with my current eating habits, and I thought about how heavy I would be if I (1) continued to eat as much as I was and (2) didn't exercise. I want to be a mobile, happy, healthy person now and in the future. Jobs will be sedentary from here on out, and I had to change my perspective on diet and exercise (and getting older, lol). I've fallen off the wagon a few times as well, and it always comes back to "Where do you want to be next month, +10 or -10 pounds? It's up to you."
Those are the thoughts that keep my eye on the prize, so to speak.