0Gorira
(0Gorira)
1
質問です。
UKismetSystemLibrary::DrawDebugStringで日本語の文字列を入れると文字化けを起こしてしまいます。
日本語を表示するためにはどうしたらよいのでしょうか?
以下は問題になっているソースコードになります
Debug::Draw3DText(get_Actor()->GetWorld(), get_Actor()->GetActorLocation(), TEXT(“テスト表示だよ!”));
void Debug::Draw3DText(UWorld* world, const FVector _center, const FString _text,const FLinearColor _color)noexcept
{
UKismetSystemLibrary::DrawDebugString(world, _center, _text, nullptr, _color, 0);
}
どなたかお手すきの際に回答していただけると幸いです。
3dRaven
(3dRaven)
2
UKismetSystemLibrary::DrawDebugString(GetWorld(), FVector(0,10,0), TEXT("で日本語の文字列を入れると文字化けを起こしてしまいます"), 0, FLinearColor::Blue,2000000);
正常に動作するようです
コンポーネント上 (spring arm component)
void UCustomSpringArmComponent::Draw3DText(const FVector _center, const FString _text, const FLinearColor _color)noexcept
{
UKismetSystemLibrary::DrawDebugString(GetWorld(), _center, _text, nullptr, _color, 0);
}
0Gorira
(0Gorira)
3
@3dRaven
返信していただきありがとうございます。
同様のソースコードを使って検証してみましたが、やはり文字化けしてしまいました。
もしかして日本語を表示するには何かプロジェクト設定を変更する必要があるのでしょうか…?

|
UKismetSystemLibrary::DrawDebugString( |
|
get_Actor()->GetWorld(), |
|
get_Actor()->GetActorLocation(), |
|
TEXT(で日本語の文字列を入れると文字化けを起こしてしまいます), |
|
0, |
|
FLinearColor::Blue, |
|
2000000); |
0Gorira
(0Gorira)
5
@3dRaven
そのフォントはどのようにすれば変更できるでしょうか?
UE初心者の身なので教えていただけると幸いです。
3dRaven
(3dRaven)
6
カスタムフォント
Project Settings => Engine =>General Settings => Fonts
デフォルトフォント
すべてのデフォルトフォントがありますか?
Edit
フォント選択付きのテキスト
.cpp
// 上部に含める必要がある
#include "GameFramework/HUD.h"
#include "Kismet/GameplayStatics.h"
void YourClass::Draw3DText(const FVector _center, const FString _text, const FLinearColor _color, UFont* _font)noexcept
{
FVector _offset = FVector(0, 0, 0);
APlayerController* pc = UGameplayStatics::GetPlayerController(GetWorld(), 0);
if(pc!=nullptr)
pc->GetHUD()->AddDebugText(_text, GetOwner(), 0, _offset, _center, _color.ToFColor(false), false, false, false, _font, 1, false);
}
すべてのフォントを試して、日本語で動作するフォントを確認してください
0Gorira
(0Gorira)
7
@3dRaven
日本語に対応したフォントが見当たらないのですが、どれの事でしょうか…?
調べてみたら
このような記事をみつけ、参考にしてフォントアセットを作成して[プロジェクト設定→基本設定→フォント]の箇所にフォントアセットをアタッチしましたが、相変わらず日本語が表示されません。(なんならフォントアセットのプレビューでも日本語だけ横になっていてまともに表示がされていない…)
