【请教】如何在C++中创建按键个事件。如图

[复制链接]
查看3725 | 回复5 | 2018-4-12 17:27:30 | 显示全部楼层 |阅读模式
【请教】如何在C++中创建这样的按键个事件。如图
S6[%XK5)VQ%RA~9BQ2PR1VR.png
我想使用
PlayerInputComponent->BindKey(EKeys::A, IE_Released, this, &AThePlayer::ChangeWeapons);
然后
void AThePlayer::ChangeWeapons(){}

9XAIASP@M(10(BLM6W1{_5M.png
但是一直提示我错误:
CompilerResultsLog: Error: ThePlayer.cpp.obj : error LNK2019: ?޷????????ⲿ???? "__declspec(dllimport) public: __cdecl FInputChord::FInputChord(struct FKey,bool,bool,bool,bool)" (__imp_??0FInputChord@@QEAA@UFKey@@_N111@Z)???÷????ں??? "public: virtual void __cdecl AThePlayer::SetupPlayerInputComponent(class UInputComponent *)" (?SetupPlayerInputComponent@AThePl
ayer@@UEAAXPEAVUInputComponent@@@Z) ?б?????
CompilerResultsLog: Error: ThePlayer.cpp.obj : error LNK2019: ?޷????????ⲿ???? "__declspec(dllimport) public: __cdecl FInputChord::FInputChord(struct FInputChord const &)" (__imp_??0FInputChord@@QEAA@AEBU0@@Z)???÷????ں??? "public: struct FInputKeyBinding & __cdecl UInputComponent::BindKey<class AThePlayer>(struct FInputChord,enum EInputEvent,class AThePlayer
*,void (__cdecl AThePlayer::*)(void))" (??$BindKey@VAThePlayer@@@UInputComponent@@QEAAAEAUFInputKeyBinding@@UFInputChord@@W4EInputEvent@@PEAVAThePlayer@@P84@EAAXXZ@Z) ?б?????
CompilerResultsLog: Error: ThePlayer.cpp.obj : error LNK2019: ?޷????????ⲿ???? "__declspec(dllimport) public: __cdecl FInputChord::~FInputChord(void)" (__imp_??1FInputChord@@QEAA@XZ)???÷????ں??? "public: struct FInputKeyBinding & __cdecl UInputComponent::BindKey<class AThePlayer>(struct FInputChord,enum EInputEvent,class AThePlayer *,void (__cdecl AThePlayer:
:*)(void))" (??$BindKey@VAThePlayer@@@UInputComponent@@QEAAAEAUFInputKeyBinding@@UFInputChord@@W4EInputEvent@@PEAVAThePlayer@@P84@EAAXXZ@Z) ?б?????
CompilerResultsLog: Error: E:\UE4gongcheng\4.18C++\TheExecutioner\Binaries\Win64\UE4Editor-TheExecutioner-7003.dll : fatal error LNK1120: 3 ???޷????????ⲿ????
CompilerResultsLog: ERROR: UBT ERROR: Failed to produce item: E:\UE4gongcheng\4.18C++\TheExecutioner\Binaries\Win64\UE4Editor-TheExecutioner-7003.dll

我该如何更正?同时我想调用图一中的Key结构体。我又该怎么做


mknmknmk | 2018-4-13 08:16:23 | 显示全部楼层
本帖最后由 mknmknmk 于 2018-4-13 08:22 编辑

请写在pawn 里
PlayerInputComponent 在actor 不存在的,


但是 你可以在 Actor 添加 UPROPERTY()   UInputComponent *PlayerInputComponent ;


构造函数里初始化它,进行绑定。添加EnableInput(this);



  或者在tick 里检检查按键是否按下。

回复 支持 反对

使用道具 举报

mknmknmk | 2018-4-13 08:24:43 | 显示全部楼层
本帖最后由 mknmknmk 于 2018-4-13 08:27 编辑

SetupPlayerInputComponent  actor里没有此虚方法
检查 Build.cs 是否 有
PublicDependencyModuleNames.AddRange(new string[] { "Core",
            "CoreUObject",
            "Engine",
            "InputCore",
            "RenderCore",
            "RHI"
        });



工程名.h 是否包含以下2两句
#include "CoreMinimal.h"
#include "Engine.h"

回复 支持 反对

使用道具 举报

mknmknmk | 2018-4-13 08:29:46 | 显示全部楼层
https://answers.unrealengine.com/questions/617654/how-can-i-create-a-player-input-component-in-an-ac.html
回复 支持 反对

使用道具 举报

mknmknmk | 2018-4-13 08:34:56 | 显示全部楼层
tick 里获取 事件
https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/533-input-held-down
回复 支持 反对

使用道具 举报

w3086379003 | 2018-4-24 13:09:00 | 显示全部楼层
mknmknmk 发表于 2018-4-13 08:16
请写在pawn 里
PlayerInputComponent 在actor 不存在的,

我这边使用的是pawn类,我BindAction和BindAxis函数都可以用,现在想尝试一下BindKey 的用法。以及想尝试下获取BindKey中Key的结构体
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

33

主题

248

回帖

763

积分

初阶编码师

积分
763