> Optimism is the precondition for doing good.
It is still possible to do good when things are bleak and there is no possible way out - just because doing good is the right thing[1]. Optimism helps a lot for morale, but is not a precondition.
1. e.g. the 2 people who were pictured comforting each other while trapped at the top of a burning wind turbine.
Optimism doesn't necessarily mean hope. It can mean belief in an afterlife. An end to a suffering. Or gratitude for having someone else in a terrible moment.
I think OP is correct. You can't have good without optimism. Your point, which is also correct, is you can do good without hope.
op·ti·mism (noun): hopefulness and confidence about the future or the successful outcome of something.
I suspect answers couched in terms of individualism will always sound inadequate to questions that are inherently collectivist, such as why people do things "for the greater good" detrimental to their own well-being.