So you may remember a few months ago, I made a post called Taking in-game screenshots with UI in Unreal Engine 4.
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:
And in the .cpp
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.
