This is at the heart of mental health - the issue being that imagined feeling patterns are formed during infancy. During that period you need to maintain relationships with your caregivers in order to survive (so your feelings organise around achieving good caregiver conditions). However when you are in the wider world as an adolescent/adult things are very different (1. don't need your caregivers to survive and 2. the rest of the world doesn't act the same way that your caregivers do) and that's when things get bad-mental-healthy. Your brain is imagining feelings to satisfy a different environment to the one you are in.
Even more amazingly the brain knows it does this and has a built in correction mechanism - dreams. They don't auto correct, but provide instructions (if we listened). This isn't the Freudian-everything-is-a-penis/vagina vibe, but a much more practical route to using dreams to diagnose false feelings. I wrote a paper on this here: https://psyarxiv.com/k6trz
When you have spotted a false feeling it's very easy to get rid of it. You have to catch yourself repeating the pattern and break it. Do that a few times and your brain reconsolidates and no longer feels the inaccurate feeling as it understands that the survival function of it is no longer required.