The problem with that post is that I was using the Cheat Manager for my implementation however, while suitable for my use case, this cannot be used in Shipping builds of your project due to Cheat Manager being one of the things UE4 strips from Shipping builds. This post will fix this in a quick and efficient way.
"So what's another way of doing it?" I hear you ask. Well, we could derive from quite a few classes but, for now, we'll derive from the Game Instance class.
Before we get into this I need to remind you of what the Game Instance is. It is the instance of your game.....yeah, that's an oversimplification. The Game Instance is the very first object created by the engine when the game is launched, after the engine's own initialisation of course, and is the final object to be destroyed when your game is closed. It exists for the entire time your game is running so it's the perfect place to put code you may always want access to which is why we're putting our new Screenshot implementation here.
So how do we do it?
Similar to the original post you need to add a new C++ class which is parented to the Game Instance class rather than Cheat Manager. Name it whatever you want.
Once that's been created and you've got it open in Visual Studio or Rider you'll need to add this code to the .h file:
Once that's done, hit compile and wait for the magic to happen. I won't go into much detail here as the code is pretty self-explanatory but if you want a more in-depth look at what's going on, check out my previous post titled; Taking in-game screenshots with UI in Unreal Engine 4.
So how do we use it?
Once that's compiled you'll need to do one small task before it's ready to go. This one's an easy one to miss if you haven't used a Game Instance before. You'll need to go into your Project Settings->Maps & Modes then scroll to the bottom to change your selected Game Instance to your newly created class.
You must do this step or the following WILL NOT work.
You can now go into any class you want, cast to your Game Instance and call TakeScreenshot from there. I'm using the Character as an example.
If you had not configured the project to use your custom Game Instance as shown above you will get an error when trying to use this cast.
Congrats! You can now take screenshots anywhere, even with UI. Sadly I didn't add UI to the project to show off. Please remember that this is a basic implementation and there are more extensive ways of taking screenshots with more features. This is just to get you going in the right direction.