What do I do when I realize all my giving and building was really so people would notice me? Was any of it ever good?
Even your wish to be noticed was something Hashem used to bring real good into the world.
The teaching does not argue with what you've discovered about yourself. Rabbi Landau tells of a man over seventy who said, "Looking back, my whole life was about seeking attention." He felt terrible about it. The Rabbi didn't tell him he was wrong about his motive. He pointed him toward what that motive had produced: "And thanks to your attention-seeking nature, look how many people you helped and what you built."
Then he said: "So perhaps Hashem uses even those false motives to bring you where you are today." The people you helped were really helped. What you built really stands. An impure root does not cancel real fruit.
The fact that you can see your motives honestly now is part of where Hashem has brought you. The same drive you feel ashamed of was the means of carrying you here, and here is a good place to stand.
“So perhaps Hashem uses even those false motives to bring you where you are today.”