1
\$\begingroup\$

I'm following this documentation, but it doesn't compile cause of "InputComponent". Unfortunately the error is not that clear even in my language.

Here's the error:

CompilerResultsLog: Error: C:\Users\Paradisee\Desktop\C++\Paper\Source\Paper\PlayerTile.cpp(83) : note: I tipi a cui si punta sono privi di relazioni. La conversione richiede reinterpret_cast, cast di tipo C o cast di tipo funzione CompilerResultsLog: ERROR: UBT ERROR: Failed to produce item: C:\Users\Paradisee\Desktop\C++\Paper\Binaries\Win64\UE4Editor-Paper-583.dll

Here's the code:

// Called to bind functionality to input
void APlayerTile::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
    Super::SetupPlayerInputComponent(PlayerInputComponent);

    // Respond every frame to the values of our two movement axes, "MoveX" and "MoveY".
    InputComponent->BindAction("MoveX", IE_Pressed, this, &APlayerTile::MoveX);
    InputComponent->BindAction("MoveY", IE_Pressed, this, &APlayerTile::MoveY);
}

This is the definition of the method MoveX():

void APlayerTile::MoveX(float AxisValue)
{

}
\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$

BindAction expects to take a FInputActionHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr as the last parameter. This is, basically, a function that takes no arguments and returns nothing. In other words, something like:

void APlayerTile::MoveX() {
  ...
} 

You're giving it a function that takes a float parameter:

void APlayerTile::MoveX(float AxisValue) {
  ...
} 

Pointers to those functions don't match because they have different signatures, and cannot be implicitly converted. The error is telling you that: that if you want to force this conversion you must use a C-style cast or a reinterpret_cast, which would make the code compile (but crash or otherwise misbehave at runtime, so that's not a solution).

You either need to change your MoveX so it doesn't take a parameter, or use BindAxis to bind it instead of BindAction. BindAxis is for "axis" inputs, which have a value associated with them representing their current state. BindAction is for "action" inputs, which don't have continuous values but rather are either "pressed" or "released."

\$\endgroup\$
5
  • \$\begingroup\$ shouldn't be the method be called every frame if the key is pressed? Cause it is not happening to me. \$\endgroup\$ Dec 8, 2017 at 17:08
  • \$\begingroup\$ No, it shouldn't. "Pressed" and "Released" actions trigger only when the key combination associated with the action is first pressed or first released. \$\endgroup\$
    – user1430
    Dec 8, 2017 at 17:14
  • \$\begingroup\$ If you want to move continously, you need to use bindAxis() and not bindAction() \$\endgroup\$
    – Raildex
    Dec 8, 2017 at 17:27
  • \$\begingroup\$ Well, my intention is to make my player move in a single direction when the game begins without pressing nothing, and be able to move constantly to other directions if he press once only. Like the game "Paper-io.io" \$\endgroup\$ Dec 8, 2017 at 17:38
  • \$\begingroup\$ If you're unsure how to do that using the UE axis/action inputs, you should post a new question about it. \$\endgroup\$
    – user1430
    Dec 8, 2017 at 17:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .