The seniors of Riverdale High graduated in this week's episode of Riverdale, and a surprise cameo appearance from the late Luke Perry left fans feeling very emotional. Because Perry died in 2019, his character Fred Andrews couldn't attend his son Archie's graduation, but the Riverdale team still found a perfect way to include him in the episode. As we'll be talking about exactly what happened in the third episode of season 5, know that there are spoilers ahead for anyone who hasn't yet watched the show.

In the Riverdale episode, titled "Chapter Seventy-Nine: Graduation," Archie (KJ Apa) ponders his next steps as his high school graduation approaches. He then has a dream of his graduation the way it should have been, with his father standing alongside Mary (Molly Ringwald) and taking photos of Archie, Veronica (Camila Mendes), Betty (Lili Reinhart), and Jughead (Cole Sprouse).

RELATED: Kiernan Shipka Will Return as Sabrina in Riverdale Crossover Event

"I can't believe we're here," Fred says in the scene. "Archie, you're graduating. I didn't think I'd live to see this day."

So, how did Riverdale manage to get footage of Luke Perry for the graduation scene? Some longtime fans of the series might remember the scene from the season 2 episode "A Kiss Before Dying." At the time, Fred was facing his own mortality after getting shot, and as he fought for his life, he dreamt of himself at Archie's graduation. Given how Fred eerily predicted that he wouldn't live long enough to see the day, the scene now takes on an entirely new meaning and fit perfectly into the new episode.

Luke Perry died suddenly in 2019 after suffering a stroke at the age of 52. Due to his death, his character Fred Andrews was also written out of the series rather than recasting him with another actor. In the season 4 premiere of Riverdale, it is explained that Fred died as a result of a hit-and-run accident. Given Perry's real-life death, the episode was incredibly emotional, and as this week's episode proved, the loss still painfully stings with fans.

"#Riverdale gutted me," tweeted one fan after watching the episode. "I'll never be over losing Luke Perry. Seeing Fred's face onscreen as Arch missed & remembered his Dad? Hits much harder now in ways I was ill-prepared for. I bawled for 10 min. It was ugly."

Another tweeted, "Not gonna lie that Fred scene made me choke up a little bit.. I cannot believe he didn't get to live to see his son graduate when no one fought harder for Archie then him. Rip Luke."

Following the graduation episode, Riverdale is moving ahead with a seven-year time jump, revealing that Archie has since joined the military and even went to war. A sneak peek teaser of the time jump episode has been released. There's much more to come as well, as The CW recently renewed Riverdale for season 6 along with a slew of other renewals. The only downside is that Perry isn't still around to be a part of the show. You can check out some of the fan reactions to Perry's cameo on the series this week below.