gpt4 book ai didi

c++ - 在 UE4.22.3 及更高版本中将用户输入绑定(bind)到 UActorComponent 方法

转载 作者:行者123 更新时间:2023-11-30 03:15:17 24 4
gpt4 key购买 nike

我正在尝试创建 UActorComponent 来处理一些用户输入。我是这样做的:

void MyComponent::BeginPlay()
{
Super::BeginPlay();
this->InputComponent = GetOwner() ->FindComponentByClass<UInputComponent>();

if (this->InputComponent != nullptr) {
UE_LOG(LogTemp, Display, TEXT("%s InputComponent Found"), *(GetReadableName()));

this->InputComponent->BindAction("MyAction", IE_Pressed, this, &MyComponent::ActionStart);
this->InputComponent->BindAction("MyAction", IE_Released, this, &MyComponent:: ActionEnd);

UE_LOG(LogTemp, Display, TEXT("%s InputComponent Binding done"), *(GetReadableName()));
}
}

但是从未调用过组件的方法。我发现调用 Pawns SetupPlayerInputComponent 方法后所有绑定(bind)都消失了。如果我在 SetupPlayerInputComponent 中进行所有绑定(bind),所有绑定(bind)都会正常工作。

那么在 UActorComponent 中处理用户输入的最佳方式是什么,或者这根本不是好的做法?

最佳答案

正如您提到的,如果您在 SetupPlayerInputComponent 中调用函数,绑定(bind)就会起作用,所以最简单的解决方案是在您的组件中创建一个名为 SetupInput 的函数并调用该函数来自你的 pawn 的 SetupPlayerInputComponent 函数。

是的,在我看来,绑定(bind)应该由受控 pawn 或玩家 Controller 处理,因为这就是 ue4 游戏框架的工作方式。如果您没有任何特定的 pawn 要控制,或者如果它只是一个相机,我会将我的所有输入移动到 Controller 内部。

关于c++ - 在 UE4.22.3 及更高版本中将用户输入绑定(bind)到 UActorComponent 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57142328/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com