ue5中怎么将actor物体作为ui渲染在屏幕上,而不随父级对象的移动产生的透视而改变大小
1条回答 默认 最新
关注不知道你这个问题是否已经解决, 如果还没有解决的话:- 以下回答来自chatgpt:
问题分析
根据问题描述,需要在UE5中实现将一个Actor的物体作为UI渲染在屏幕上,并且不希望其受到父级对象移动时产生的透视效果影响而改变大小。
解决方案
要实现这个效果,可以通过以下步骤来完成:
- 创建一个Widget蓝图,并添加一个Overlay容器和一个Image控件作为子控件。
WidgetBlueprint'/Game/PathToYourWidgetBlueprint.YourWidgetBlueprint'- 在蓝图的构造函数或者OnConstructed函数中,创建一个WidgetComponent,并设置其Widget Class为上一步创建的Widget蓝图。
// 在Actor类的构造函数或者OnConstructed函数中添加以下代码 UWidgetComponent* WidgetComponent = CreateDefaultSubobject<UWidgetComponent>(TEXT("MyWidgetComponent")); WidgetComponent->SetupAttachment(RootComponent); WidgetComponent->SetWidgetClass(UYourWidgetClass::StaticClass()); // 替换成你的Widget蓝图的类名 WidgetComponent->SetDrawAtDesiredSize(true);- 在Actor类的BeginPlay函数中,设置WidgetComponent的DrawSize为屏幕尺寸,并禁用父级对象的缩放。
// 在Actor类的BeginPlay函数中添加以下代码 if (UWorld* World = GetWorld()) { if (APlayerController* PlayerController = World->GetFirstPlayerController()) { FVector2D ViewportSize; PlayerController->GetViewportSize(ViewportSize); WidgetComponent->SetDrawSize(ViewportSize); WidgetComponent->SetRelativeScale3D(FVector(1.0f, 1.0f, 1.0f)); // 禁用父级对象的缩放 } }- 在Widget蓝图中,将Overlay容器和Image控件的大小设置为相同,并选择需要渲染的物体作为Image的图像。
// 在你的Widget蓝图中添加一个Overlay容器和一个Image控件,并设置它们的大小相同 // 在Image控件中选择需要渲染的物体作为图像结论
通过以上步骤,可以在UE5中实现将一个Actor的物体作为UI渲染在屏幕上,并且不受父级对象移动时产生的透视效果影响而改变大小。
如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用 1- 以下回答来自chatgpt: