Before the end credits of Sonic movie 4, there is a scene where a portal appears in the heart of Green Hills Town, from there emerge two figures: Carbuncle, the mascot of the Puyo Puyo series who is CGI, and it's owner: Arle Nadja (with a fire ball in one hand and and an ice ball in the other) a live-action girl. She opens up a map depicting multiple worlds based on Sega franchises, some person passes and the stalks them by showing them a crudely drawn picture of Sonic. Yes, we have Puyo characters before Silver, Blaze, Cream or the Chaotix
The movie starts with Selvaria Bles using her witch powers to search for multiple power sources beyond her world, one of which being the Master Emerald which resides on Earth.
Back on Earth, Team Sonic (which also includes Amy) are invited as guest of honors to the high school graduation of Tom and Maddie's daughter, where we have many wacky hijinks during the party, then Arle and Carbuncle crashes and mood-whiplashes with a speech about an evil woman stealing multiple magic artifacts to become the strongest, Sonic thinks she's crazy but she shows evidence by showing a damaged helmet of Death Adder (Golden Axe) and Ren Amamiya's mask shattered in two. And then reveals that the rings can be powered by the Master Emerald to travel realities beyond. After quitting the place, the team attempts to use the Emerald to power the rings, in the last one it works. So Sonic, Tails, Knuckles, Amy, Arle and Carbuncle all enter it and end up in Nightopia, which was usurped by the white-haired meanie. They encounter a weakened Nights and so joins the gang.
Maddie and Tom think about having another child, but a portal from the future appears in their face and from there emerges Edgar from Quartet (who is the Wachowskis' great-great-grandchild).
Back on Sonic, the gang discovers that the Master Emerald is getting debilitated, and Selvaria appears back on them. It starts a fight sequence, the witch is a one-woman army, and easily defeats the four anthros, and then Arle releases a Bayoen which leaves her weak for a short time. Nights uses the Master Emerald and one of the rings to get out of here, but the woman began chasing them.
Meanwhile, Tom and Maddie are on a galactic sci-fi fight with help of the Quartet squad lead by Mary.
Next is a montage of Sonic and friends travelling to other Sega worlds while Selvaria chases them, in Fantasy Zone they encounter Opa-Opa, in Radaxian they found Alex Kidd, ect. If you want to see how many games they travel check out https://sega.fandom.com/wiki/List_of_Sega_franchises
By some mishap, Sonic and Tails accidentally end up getting separated by the rest, and they find themselves on a neon-grid world full of Sega references and they find a door. It's the room of the Sega Hard Girls and they found the Hedgehog and the two-tailed fox. They reveal they are the guardian goddesses of the Segaverse (which is going to be the name of Sega's retro game digital platform to play older titles), and they see the screen which shows a map of the Sega worlds disappearing, Sonic is confused and Mega Drive helps him out of his breakdown. and so Professor Asobin (voiced by Naoto Ohshima) also joins, so Sonic, Tails and the girls go back with the army of survivors (which includes Sakura Shinguji, Phantom R, Love & Berry, Sega Taro, ect.) and surprinsingly Tom, Maddie and the Quartet team are there and want to fight and Knuckles still has the Master Emerald on his hands.
An old man named Professor Games wants him to bring him the Emerald, not knowing he's Selvaria in disguise. Knuckles is not a fool, and so Selvaria reveals herself and there is a hot potato fight of who gets the Emerald. and in process it gets destroyed and it becomes the 7 chaos emeralds. Sadly. Selvaria grabs all of them and also steals the rings. Sonic is sad, but the platoon makes him recover and the SHG and Asobin send all of them to their world.
Selvaria suddendly appears on Sonic's home dimension by combining all the artifacts she found during her rampage and she becomes a kaiju monster attacking the anthropomorphic animals living them. Sonic and co. is horrified so they all go there.
There is a giant fight full of cameos everywhere, and Sonic enters inside the monster which reveals Selvaria is just controlling like a war tank, Sonic tricks her on getting the Emeralds. and they fight inside, and suddendly the ghost of Robotnik appears and reedems himself as he steals the emeralds from Selvaria. Sonic turns into Super Sonic and he grants the ghost a super shield so they can fight her.
Sonic calls the Sega Space Patrol to put Selvaria in prison, Sonic suddendly discovers Razorclaw is alive and they reunite. and she now wants to live with Sonic and his family. Everyone elso go back to their worlds. and Sonic does a family photo with everyone.