TakeHighResScreenshot function outputs the wrong camera view

I have an editor callable event, that initally just called TakeHighResScreenshot with the desired camera plugged in, but that just took a screenshot from the viewport camera. So I tried changing the view target to the desired camera and then running TakeHighResScreenshot. Now it swaps to the desired camera for a split second, takes a screenshot and then swaps back to the previous view, which seemed promising at first, until I looked at the output and saw that it just took a screenshot of the original view anyway.

Anyone got an idea of how to get this to take a screenshot from the right camera?