I have tried many variation of the following code, none of which worked for me, meaning nothing gets copied to the Clipboard. My goal is to copy something from the game (a string) into the clipboard.
// Fill out your copyright notice in the Description page of Project Settings.
#include "GenericPlatform/GenericPlatformApplicationMisc.h"
#include "Clipboarduwu.h"
FString UClipboarduwu::happay(FString s)
{
TCHAR tc[100];
char txtToCopy[11] = "hellohello";
for (int i = 0; i <= strlen(txtToCopy); i++)
{
tc[i] = txtToCopy[i];
}
FGenericPlatformApplicationMisc::ClipboardCopy(tc);
return tc;
}
The above code compiles and links fine, BUT it does not copy anything into the clipboard.
I have tried the non-generic version but it would not compile, or it would not recognize the header.
Please, can you help me understand what I am doing wrong?
I know the code runs, because I can see the returned value (“hellohello”) in game when calling it, but the clipboard remains untouched.
you hit the classic generic trap, FGenericPlatformApplicationMisc is the stub that does nothing on most platforms, the real call is FPlatformApplicationMisc::ClipboardCopy with HAL/PlatformApplicationMisc.h and ApplicationCore in build.cs, which is what hyaniner posted.
if you run into this again on the next engine version or just dont want a C++ module for one feature, Runtime Clipboard Utility, a Blueprint clipboard plugin for Unreal Engine 5, wraps the same calls as Copy / Paste nodes so theres no header or module to maintain, free, covers 5.0-5.8 including packaged builds: Runtime Clipboard Utility — Free Copy & Paste Text Nodes for Blueprints (UE5) | Fab
also drop the manual TCHAR loop, just pass *YourFString straight in, the char-by-char copy is where silent truncation usually sneaks in.