From Wikipedia: SpongeBob has been entrusted by Mr. Krabs to keep the Krabby Patty formula safe. But in all the excitement, SpongeBob forgets where he put the formula. He then relies on the help of the most unlikely companion, Plankton. With the help of his friends, SpongeBob must use Plankton's memory machine to retrace the happiest moments of his life (because according to SpongeBob, he's unable to remember anything when he's sad) to find the Krabby Patty formula in time for the Krusty Krab's "eleventy-seventh" anniversary. Little does SpongeBob know, however, that Plankton wants the formula for himself and has inserted robots into SpongeBob's memories to extract the precise location of the formula. But after breaking the controller, Plankton has no choice but to go inside SpongeBob's memories instead. SpongeBob travels through his memories, fighting robots and robot bosses that look like Patrick and Squidward. He travels various environments as he relives his memories, such as getting his job as fry-cook, meeting Sandy as well as practicing karate with her, his first Christmas, his first 24-hour shift (where he's lost in Rock Bottom), jellyfishing with Patrick, meeting Mermaidman and Barnacleboy, Squidward's first Krabby Patty (where his fights Squid-Bot), and his fake fight with Patrick to get into the Salty Spittoon (where he fights Pat-Bot). He then remembers the formula is in the Krusty Krab safe. Plankton finds this out however and turns the entire Chum Bucket into one giant Plankton-Bot. After destroying it, SpongeBob tells Mr. Krabs the formula is in the safe, but then finds out it was in his back pocket the whole time. However, when he gives the paper to Mr. Krabs, he realizes that he gave him his lottery ticket and that the secret formula was in Mr. Krabs' back pocket the whole time.