Screenshot before aborting play, is it possible?

So what I practically want is that whenever the engine aborts a play or simulate because of an infinite loop or whatever reason; take a screenshot and saving the picture to some location before aborting.
It would be really useful, I sometimes record constantly with OBS but it’s a bit of a bother and easy to forget.

But I don’t really know much about C++ or the engine so I don’t know how to do it, if it is even possible.