Thanos, after conquering his destiny over many multiverses, has come to his last universe to destroy. In order for the team to win, Sonic has to get his chaos emerald from the Western Gang.
Tails, being the inexplicable Mexican he is, decides to eat a bunch of tacos, until his big taco magically flies away. He gets pissed, and almost kills the weird Spider-Man like figure, until he gives him the big taco, and chaos emerald.
Being sent back to time, Shadow goes back to his time-line when he was first being created, and goes back to NYC to get Sonic's Chaos emerald, also sending Scourge back to the main time-line, which he wasn't supposed to.
Rouge and Espio are sent back to time in 2014, when the crew was going in the helicarrier. Rouge and Espio had to steal 1 chaos emerald in order to get sent back to their present time-line.