Accidentally Took out the wrong engine cap in my Motorcycle while trying to drain the Engine Oil?

My Motorcycle is a Honda XRM. I was trying to change engine oil but opened a different screw/cap just beside the engine oil drain.A 5 inch long spring and a rod with holes came out, i put it back the way i think it should be, then opened the Drain cap, drained the engine oil and filled it with new oil.
But when i start the motorcycle it sounded like there's something loose moving inside the engine.
What is the rod and spring that came out? Is it critical?

You might be talking about the oil strainer. If you screwed it up, you would have starved the engine of oil and trashed it.

Of course it's critical. There was probably a steel ball that fell out that the spring tensions to select the gears with. Find it and put it back in. You may get lucky. Don't run the motor until you get it straightened out. Go to the dealer and with any luck the parts department can bring up a picture of the parts that came out in case you need to order the ball you missed.