UE4在屏幕上的打印位置
UE4 Printing Location on Screen
我想在游戏开始时在屏幕上看到我的演员的位置。
我试过这个:
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString::Printf(TEXT("LOCATION: %f"), Location));
。.cpp
FVector Location = GetActorLocation();
FRotator Rotation = GetActorRotation();
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString::Printf(TEXT("LOCATION: %f"), Location));
但它给出了一个编译错误,例如:
解析 SHOULDWORKEditor 的标头
Running UnrealHeaderTool "C:Users840-g5DocumentsUnreal ProjectsSHOULDWORKSHOULDWORK.uproject" "C:Users840-g5DocumentsUnreal ProjectsSHOULDWORKIntermediateBuildWin64SHOULDWORKEditorDevelopmentSHOULDWORKEditor.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -installed
Reflection code generated for SHOULDWORKEditor in 7,2799668 seconds
Using Visual Studio 2019 14.22.27905 toolchain (C:Program Files (x86)Microsoft Visual Studio2019EnterpriseVCToolsMSVC14.22.27905) and Windows 10.0.18362.0 SDK (C:Program Files (x86)Windows Kits10).
Building 4 actions with 8 processes...
[1/4] MyActor.cpp
C:Program FilesEpic GamesUE_4.22EngineSourceRuntimeCorePublicContainers/UnrealString.h(1393) : error C2338: Invalid argument(s) passed to FString::Printf
C:Users840-g5DocumentsUnreal ProjectsSHOULDWORKSourceSHOULDWORKMyActor.cpp(26): note: see reference to function template instantiation 'FString FString::Printf<wchar_t[13],FVector>(const FmtType (&),FVector)' being compiled
[
with
FmtType=wchar_t [13]
]
EDIT Tried this:
Location.ToString()
and got the same error
and tried this:
FString LocString = Location.ToString();
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString::Printf(TEXT("LOCATION: %s"), LocString));
and i got the error:
C:Program FilesEpic GamesUE_4.22EngineSourceRuntimeCorePublicWindows/WindowsPlatformNamedPipe.h(12): note: see declaration of 'FString'
C:Program FilesEpic GamesUE_4.22EngineSourceRuntimeCorePublicContainers/UnrealString.h(1395): note: the constructor and destructor will not be called; a bitwise copy of the class will be passed as the argument
C:Program FilesEpic GamesUE_4.22EngineSourceRuntimeCorePublicContainers/UnrealString.h(73): note: see declaration of 'FString::FString'
C:Program FilesEpic GamesUE_4.22EngineSourceRuntimeCorePublicContainers/UnrealString.h(1395): note: 'FString::FString' is non-trivial
C:Program FilesEpic GamesUE_4.22EngineSourceRuntimeCorePublicContainers/UnrealString.h(1395) : error C4840: non-portable use of class 'FString' as an argument to a variadic function
虚幻记录器需要一个指向FString的指针,下面是一个关于如何打印矢量的电子示例:
//"MyCharacter's Location is %s"
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Location is %s"),
*MyCharacter->GetActorLocation().ToString());
有关所有日志示例和文档,您可以在此处查看: https://wiki.unrealengine.com/Logs,_Printing_Messages_To_Yourself_During_Runtime
我不知道你是否想通了这一点,但事实证明,将 FString 返回给 Printf,你必须先取消引用:
GEngine->AddOnScreenDebugMessage(-1,200,FColor::Green,FString::Printf(TEXT("Hello %s"),*GetActorLocation().ToString()));
这在虚幻文档网站底部有简要描述。
我测试了它,它似乎有效。
相关文章:
- 我正在尝试为字符打印一些相应的值,但条件总是转到其他位置
- UE4在屏幕上的打印位置
- 为什么我的字符串在错误的位置打印
- C 比较数组中的元素并打印位置
- 递归功能,以打印每个新位置以进行控制
- 打印指针指向的内存位置和值
- 如何获得精灵的实际位置并将其打印在C 和SFML中
- 如何查找子字符串的位置并从那里打印它
- 使用流来打印点之后的最大十进制位置
- 如何从clang ast节点打印源位置
- 全局声明QStringlist变量,使用QFileDialog获取位置路径并将其打印到lineEdit并在QProces
- 如何在 c++ 中打印字母和符号后保留在一个位置
- 使用cout从特定位置开始打印
- 在C++中,有一种方法可以从不同的内存位置打印char*
- COUT只在内存中打印位置的c++问题
- 如何在vc++ Win32应用程序中打印句子在鼠标光标的位置
- 每5、10和最后一个位置打印唯一的字符串
- 我如何打印4个不同字母组合成2个字母对的所有方式来填充4个位置,每个字母正好出现两次
- 打印以在c++中的行上的特定位置输出
- 使用boost::program_options打印普通参数和位置参数的帮助