i can complie with this, but when i package it, it shows me message “cannot find interface declaration for ‘Screenshooter’”
Anyone helps???
Got the same issue - any solution?
I know this post is bit old, but helped me a lot (thanks to andreischwingel )
I just had to change some points in your code, so the objective-c ios code works. If anyone stumbles over this post with the same issue, here my solution:
At first I didn’t made an extra actor just put the code in an custom Gameinstance h and cpp file, so you could use the methods all over your project just getting the gameinstance and casting it to your blueprint made with the cpp class as parent.
-
Make a cpp Class of the Gameinstance and add the following before the class declaration, at best after ‘# pragma one’ and before your other includes:
#include "GameFramework/Actor.h" #if PLATFORM_IOS #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> @interface Screenshooter : UIViewController <UINavigationControllerDelegate> @end #endif
-
after class declaration
UCLASS() class MyGameInstance : public UGameInstance { GENERATED_BODY()
add
public:
UFUNCTION(BlueprintCallable, Category = "Screenshooter")
bool IsScreenshotDone(FString savePath);
UFUNCTION(BlueprintCallable, Category = "Screenshooter")
FString RequestNewScreenshot();
//I didn't used the deleteimagemethod
//UFUNCTION(BlueprintCallable, Category = "Screenshooter")
// void DeleteCurrentImage();
UFUNCTION(BlueprintCallable, Category = "Screenshooter")
void SaveNativeScreenshot();
-
in the gameinstance.cpp add following:
#include “Misc/Paths.h”
#if PLATFORM_IOS #include "IOSAppDelegate.h" #endif #if PLATFORM_IOS //@interface Screenshooter : NSObject //+ (Screenshooter*)GetDelegate; //@end @implementation Screenshooter + (Screenshooter*)GetDelegate { static Screenshooter* Singleton = [[Screenshooter alloc] init]; return Singleton; } -(void)saveShot { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex : 0]; const char *dD = [documentsDirectory UTF8String]; if (documentsDirectory == nil) { UE_LOG(LogTemp, Warning, TEXT("NoDir")); } NSString *filePath = [documentsDirectory stringByAppendingPathComponent : @"/<Your_App_Name>/Saved/Screenshots/IOS/Image.png"]; const char *fP = [filePath UTF8String]; UE_LOG(LogTemp, Warning, TEXT("File: %s"), fP); if (filePath == nil) { UE_LOG(LogTemp, Warning, TEXT("NoFile")); } NSLog(@"Print FilePath: %@", filePath); UIImage *image = [UIImage imageWithContentsOfFile : filePath]; if (image == nil) { UE_LOG(LogTemp, Warning, TEXT("NoImage")); } UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); } +(void)saveScreenshotNative { [[Screenshooter GetDelegate] performSelectorOnMainThread:@selector(saveShot) withObject:nil waitUntilDone : NO]; } @end #endif bool MyGameInstance::IsScreenshotDone(FString savePath) { return FPaths::FileExists(*savePath); } FString MyGameInstance::RequestNewScreenshot() { FString filename = "Image.png"; FScreenshotRequest::RequestScreenshot(filename, true, false); return FScreenshotRequest::GetFilename(); } void MyGameInstance::SaveNativeScreenshot() { #if PLATFORM_IOS [Screenshooter saveScreenshotNative]; #endif }
-
in your blueprints make a method in your gameinstance_bp
and for example call it this way from a umg widget
Hope anyone can use this.
Regards.
Your code worked for me like a charm…
Thank you so much…