ue5中怎么将actor物体作为ui渲染在屏幕上,而不随父级对象的移动产生的透视而改变大小
不知道你这个问题是否已经解决, 如果还没有解决的话:根据问题描述,需要在UE5中实现将一个Actor的物体作为UI渲染在屏幕上,并且不希望其受到父级对象移动时产生的透视效果影响而改变大小。
要实现这个效果,可以通过以下步骤来完成:
WidgetBlueprint'/Game/PathToYourWidgetBlueprint.YourWidgetBlueprint'
// 在Actor类的构造函数或者OnConstructed函数中添加以下代码
UWidgetComponent* WidgetComponent = CreateDefaultSubobject<UWidgetComponent>(TEXT("MyWidgetComponent"));
WidgetComponent->SetupAttachment(RootComponent);
WidgetComponent->SetWidgetClass(UYourWidgetClass::StaticClass()); // 替换成你的Widget蓝图的类名
WidgetComponent->SetDrawAtDesiredSize(true);
// 在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控件中选择需要渲染的物体作为图像
通过以上步骤,可以在UE5中实现将一个Actor的物体作为UI渲染在屏幕上,并且不受父级对象移动时产生的透视效果影响而改变大小。