– The end was shockingly sudden, but the road that led to Robin Williams' apparent suicide at age 63 was a long one — and there were plenty of signposts indicating trouble along the way.

Williams' closest friends knew well that beneath his manic exterior, the actor had battled depression for years.

In recent months — as Williams wrestled with the cancellation of his CBS TV series "Crazy Ones" and fought to maintain sobriety — those friends could see that he was losing that fight.

"He started to disconnect," said comedian Rick Overton, a friend of Williams' since the 1970s. "He wasn't returning calls as much. He would send texts … but they would get shorter and shorter."

Comedian and longtime friend Steven Pearl ran into Williams at a barbecue in July, and he could see that something was wrong. Williams had just come out of a stint in rehab in Minnesota, where he had gone, his publicist said, to "fine-tune and focus" on his commitment to his sobriety.

"You could just tell something was off," Pearl said. "He seemed detached. It's hard to explain. He didn't seem like his usual self. My fiancé and I were like, 'Is he OK?' I didn't know it would get this dark."

Williams no longer pulled in the big paydays he had in his earlier career and, with tens of millions of dollars in divorce settlements from his first two marriages, he found himself with money problems.

He returned to television last fall in the CBS comedy "The Crazy Ones."

"I have two [other] choices: Go on the road doing stand-up, or do small, independent movies working almost for scale," Williams told Parade magazine in 2013. "There are bills to pay."

Williams also decided to part with a 640-acre ranch in Napa. "I just can't afford it anymore," Williams told Parade.

On May 10, CBS announced "The Crazy Ones" wouldn't return. He took it hard, Overton said. "He got real quiet. I've known those eyes for decades. I know where the spark is supposed to be."

In early July, Williams checked himself into the Hazelden addiction treatment center. He had not fallen off the wagon, his publicist said at the time, but was struggling under the weight of depression.

What transpired in the weeks between Williams' return from Hazelden and his death is unknown except to those closest to the actor. It may never be clear what fueled the darkness that haunted him.