Speaking at the London premier of his new movie, Hector and the Search for Happiness, the British actor spoke about the tragedy.
Williams was found hanged at his home near San Francisco on Monday aged 63. The actor provided the voice of a dog in forthcoming film Absolutely Anything, in which Pegg stars.
Pegg said: "He was an extraordinary man and performer, and I think his death just highlights what a serious problem depression is. People assume if you live in Hollywood and you're rich and famous you must be happy. That's not what brings you happiness, it comes from somewhere else."
"If anything positive can come from such an awful thing, it's that people will maybe take depression a bit more seriously."
Reports yesterday suggested that twice divorced Williams was facing money troubles that had forced him to sell his California ranch and accept a string of roles in movies to pay the bills.
His actress daughter Zelda Williams, 25, has abandoned her social media accounts following "cruel and unnecessary" messages sent to her following her father's death. She deleted three accounts and said she was stepping away from social media, possibly forever.
She had been upset by two online users who had sent her disturbing images and made verbal attacks.
She had earlier joined her brothers, 23-year-old Cody and 31-year-old Zak, in paying personal tributes to their father.
Ms Williams said he was "one of the kindest, most generous, gentlest souls I've ever known.
She added: "While there are few things I know for certain right now, one of them is that not just my world, but the entire world is forever a little darker, less colourful and less full of laughter in his absence. We'll just have to work twice as hard to fill it back up again."