Wilson and Williams met while they were working together on the 2014 comedy sequel Night at the Museum: Secret of the Tomb, in which she appeared as a museum security guard.
The 42-year-old Pitch Perfect star told The Hollywood Reporter that Williams asked to speak to her after a take in which she was improvising alongside the film's lead Ben Stiller.
She said: "I wanted to chat with him but had always tried to be respectful and not bother him. We sat for about 40 or 45 minutes in between turnarounds of the camera and he said that I should be doing drama.
"I was surprised because I don’t know how he watched that scene I just did and thought I should be doing drama but he said: 'You should 100 percent be doing drama as well'. It really stuck with me."
The star has since taken on her first dramatic lead in new movie The Almond and the Seahorse, which is adapted from a 2008 play by Kaite O'Reilly.
The film follows Wilson as an archaeologist navigating her husband's traumatic brain injury, who finds comfort in a woman (Charlotte Gainsbourg) who is in a similar boat with her wife.
"I always thought, if Robin Williams thought I could do it, then I may as well give it a try," said Wilson.
She added: "So we’ve been looking for a project and then Almond and the Seahorse came up. It’s a very challenging script and really gutsy so I thought, let’s give it a go."
Williams was renowned for his ability to switch from broad comedy to darker and more dramatic material in films like One Hour Photo and Insomnia.
Read more: Comedians who went dark on the big screen
Wilson pointed to Olivia Colman as another star who has been able to make the transition in recent years, saying that "her career trajectory is amazing and she’s played so many incredible roles".
The Almond and the Seahorse is in limited US cinemas and on streaming platforms from 16 December, with no UK release confirmed thus far.
Watch: Rebel Wilson says on-screen kiss with Charlotte Gainsbourg changed her love life