Download

Problems with simple controller

I’m trying to do a very simple exercise of setting up an object that reacts to the space bar being pressed. As I understand it I have to create a Controller in order to do this, so I’ve created a PlayerController with the following source file:



#include "MyPlayerController.h"
#include "Runtime/Engine/Classes/Components/InputComponent.h"
#include "Runtime/Slate/Public/Framework/Commands/InputChord.h"
#include "Runtime/InputCore/Classes/InputCoreTypes.h"

void AMyPlayerController::SetupInputComponent() {
    Super::SetupInputComponent();
    InputComponent->BindKey(FKey("Space"), IE_Pressed, this, &AMyPlayerController::doSpacePressed);
}

void doSpacePressed() {
    _sleep(2000);
}


However, this refuses to compile with the error:



MyPlayerController.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl FInputChord::FInputChord(struct FKey)" (__imp_??0FInputChord@@QEAA@UFKey@@@Z) referenced in function "private: virtual void __cdecl AMyPlayerController::SetupInputComponent(void)" (?SetupInputComponent@AMyPlayerController@@EEAAXXZ)


I have checked that my call to BindKey matches the prototype given, so it seems that for some reason Unreal is failing to include the appropriate LIB file in the compiler configuration? I’m not sure why the error refers to FInputChord when I called the FKey variant of BindKey (I did try changing it to create an FInputChord but it gave the same message)

How can I tell it to do this, or am I doing something else wrong here?

(Also, why does Unreal seem to love creating unnecessary extra copies of Visual Studio? I have to remember NOT to click on the errors in the log because instead of highlighting the active line in the running copy, it’ll launch another instance and devour system resources.)

I think I have fixed that problem, by uncommenting the Build line that refers to Slate UI.

The problem is that the input key still doesn’t do anything.


#include "MyPlayerController.h"
#include "Runtime/Engine/Classes/Components/InputComponent.h"
#include "Runtime/Slate/Public/Framework/Commands/InputChord.h"
#include "Runtime/InputCore/Classes/InputCoreTypes.h"
#include "Runtime/Core/Public/GenericPlatform/GenericPlatformProcess.h"

void AMyPlayerController::SetupInputComponent() {
    Super::SetupInputComponent();
    InputComponent->BindKey(FKey("l"), IE_Pressed, this, &AMyPlayerController::doSpacePressed);
}

void AMyPlayerController::doSpacePressed()
{
    GetOwner()->AddActorLocalOffset(FVector(10.0, 0, 0));
    FGenericPlatformProcess::ConditionalSleep(]() {return false;}, 2000);
}


Pressing l or any other key doesn’t cause the owner (a basic cube object) to move.

1 Like

thanks i was able to get it to work