Courtesy of DisneyPaul McCartney recently confirmed that he’ll appear in the fifth Pirates of the Caribbean film. Now, the movie’s producer, Jerry Bruckheimer, has revealed how the former Beatle got the gig.

In an exclusive video interview, Bruckheimer tells Yahoo Movies UK that McCartney signed on after another rock legend bowed out of the project.

Keith Richards, who was in a couple of previous Pirates movies, was on tour and unavailable,” the Hollywood mogul explains.

The Rolling Stones guitarist, who played the father of star Johnny Depp‘s character Jack Sparrow in the third and fourth Pirates films, was busy with his band’s 2015 Zip Code Tour when the new flick was shooting.

Bruckheimer points out that Depp and McCartney are buddies who have “worked together in the past,” so Johnny “picked up the phone, called Paul [and] said, ‘Paul, you want to be a pirate?,’ [and] Paul said, ‘Sure I’ll be a pirate!'”

According to Yahoo Movies UK, McCartney plays Sparrow’s uncle, who also is named Jack, and appears in a humorous scene set in a prison where Depp’s character is being led to his execution.

“[McCartney] knew his lines, he was on time. He’s just a real gentleman,” gushes Bruckheimer. “Wonderful to work with, and came up with some really funny stuff too.”

Also in the video interview, Geoffrey Rush, who plays Captain Barbossa, says working with Sir Paul was great, while noting that he appears in “a very nice little scene where [he] has a bit of a sing and has some quite absurdist dialogue.”

Javier Bardem, who portrays the vengeful Captain Salazar, adds, “I’ve seen the movie three times now, and it makes me laugh every time. I think he’s so good in it.”

Pirates of the Caribbean: Dead Men Tell No Tales opens in U.S. theaters Friday, May 26.

Copyright © 2017, ABC Radio. All rights reserved.