Star Wars: The Last Jedi's writer and director Rian Johnson has been discussing one of the film's most-talked about and surprising scenes, involving a cameo fans had not expected.

Johnson discussed the scene in question, which takes place towards the end of the film's second act, with Collider, explaining the thought process behind the big reveal and how it could have been very different.

Big spoilers for The Last Jedi follow:

The scene in question takes place on Ahch-To, where we found Luke Skywalker (Mark Hamill) at the end of 2015's The Force Awakens.

Here he meets Rey (Daisy Ridley) and reluctantly decides to teach her about the force and why he believes the Jedi should end.

After Luke reveals what happened when Kylo Ren (Adam Driver) turned to the dark side, Rey confronts him and soon leaves. In a fit of anger, Luke goes to the tree where the original Jedi texts are housed, with the intent of burning it down.

He fails, only for the ghost of Jedi Master Yoda (Frank Oz) to appear summoning a lightning bolt and burning the tree for him, before having a quick, wisdom-filled chat.

It marks Yoda's first appearance in the series since 2005's Revenge of the Sith.

Johnson discussed with Collider how the scene came about, and why it was Yoda that appeared to Luke rather than Obi-Wan Kenobi or his father Anakin. It turns out the answer was simply down to film-making logistics.

Star Wars The Last Jedi
Mark Hamill as Luke Skywalker in the latest instalment of Star Wars, The Last Jedi LucasFilm

"Yoda, I came to the realisation pretty early, once I realised Luke's arc, that Yoda would be able to play a great place in it. The reason he's in it, though, is because he has a relationship with Luke going back, and he can speak truth to power. He can come in and set Luke straight.

"The truth is, Anakin would, I guess, be Hayden [Christiansen] who would be young Anakin, who Luke never had a relationship with that version of Anakin, so there would not be that emotional connection there for Luke. Similar with Obi-Wan. I would have loved to have brought Ewan [McGregor] in, but the truth is, Luke never had a relationship with young Obi-Wan, it was without Alec Guinness and I didn't want to create a digital version of Alec Guinness.

"So, Yoda was the obvious go-to in terms of if Luke is going to have a point of connection to the past that's going to kind of kick his butt, then we can recreate Yoda and we can bring Frank Oz in to do it, and besides, that'll be really fun."

The scene features a physical Yoda puppet that was in fact cast from the original molds used for the very first Yoda puppet in 1980's The Empire Strikes Back.

It is one of many scenes that have sparked fierce discussion since the film was released last week (14 December in the UK, 15 December everywhere else). Inevitably the sequel has been a box office hit, earning Disney the second biggest opening weekend haul of all time - just behind The Force Awakens.

It made more than $450 million on its first weekend, meaning it is on track to be one of the highest-grossing films of all time.