当游戏开始时,我希望能够在屏幕上看到我的演员位置。
我尝试了以下方法:
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:\Users\840-g5\Documents\Unreal Projects\SHOULDWORK\SHOULDWORK.uproject" "C:\Users\840-g5\Documents\Unreal Projects\SHOULDWORK\Intermediate\Build\Win64\SHOULDWORKEditor\Development\SHOULDWORKEditor.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 Studio\2019\Enterprise\VC\Tools\MSVC\14.22.27905) and Windows 10.0.18362.0 SDK (C:\Program Files (x86)\Windows Kits\10).
Building 4 actions with 8 processes...
[1/4] MyActor.cpp
C:\Program Files\Epic Games\UE_4.22\Engine\Source\Runtime\Core\Public\Containers/UnrealString.h(1393) : error C2338: Invalid argument(s) passed to FString::Printf
C:\Users\840-g5\Documents\Unreal Projects\SHOULDWORK\Source\SHOULDWORK\MyActor.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 Files\Epic Games\UE_4.22\Engine\Source\Runtime\Core\Public\Windows/WindowsPlatformNamedPipe.h(12): note: see declaration of 'FString'
C:\Program Files\Epic Games\UE_4.22\Engine\Source\Runtime\Core\Public\Containers/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 Files\Epic Games\UE_4.22\Engine\Source\Runtime\Core\Public\Containers/UnrealString.h(73): note: see declaration of 'FString::FString'
C:\Program Files\Epic Games\UE_4.22\Engine\Source\Runtime\Core\Public\Containers/UnrealString.h(1395): note: 'FString::FString' is non-trivial
C:\Program Files\Epic Games\UE_4.22\Engine\Source\Runtime\Core\Public\Containers/UnrealString.h(1395) : error C4840: non-portable use of class 'FString' as an argument to a variadic function
Location
视为浮点数似乎非常可疑。请包含完整的错误消息。 - molbdnilo