How does MV handle music after battles?

I have a common event that turns on random encounters as part of the story. in short, it's a mental dive ability to scan the area, thus making encounters a thing when they otherwise aren't. I play a specific song for this too. it works fine enough. I turn it back to the map music right before battle. But... for some reason after battle, it doesn't play the map music, but instead plays the music from the common event.

I'm guess I'm curious is there a reason it'd do that considering I turn back on the map music before battle starts (mainly because I figured this might happen if I didn't).

I should just be able to continue the map music right? especially if it's already playing again. or is there something I'm not understanding about how MV handles music after battle.
By default the BGM/BGS is saved on battle "launch", i.e. when the map scene stops and the encounter effect starts (Scene_Map#launchBattle <- Scene_Map#stop <- SceneManager.goto). Plugins can change that.

Edit: otherwise, assuming your encounter event is Parallel, it might be something to do with that? I'm not sure if Parallels restart after battle, haven't tested.
I was curious if a plugin might've changed things. I'll have to check and see.

Actually I have a question as I'm unsure what I'd look up for an answer. does this "launch" start as soon as a random encounter is triggered or is it not until the actual battle transition. because if it's the former, I know exactly why this isn't working lol... I'm changing the music too late.

EDIT: I think I've fixed this actually.

I looked for the code of when battles launch and also looked up the map bgm script call. made an edit and put if a switch is on, to instead play the map bgm right before launching and then it get's saved this way.
The currently playing BGM is saved at the start of battle. So if your common event changes the BGM, and that is what's playing when the battle begins, that's what will play when the battle ends.

Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/how-does-mv-handle-music-after-battles.155689/