Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Unhandled exception when running code.

The program is meant to log a message whenever the player presses a key, but when i run the code , i get the following error.

 Unhandled exception at 0x000007FEE193791A (UE4Editor-Engine.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x00000000000000B8.

The code is:

 #include "ClientMessage.h"
 #include "MyPawn.h"
 AMyPawn::AMyPawn(const class FPostConstructInitializeProperties& PCIP)
     : Super(PCIP)
 void AMyPawn::SetupInputComponent()
     InputComponent->BindAction("printStuff", IE_Pressed, this, &AMyPawn::printMessage);
 void AMyPawn::printMessage()
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("This is an on screen message!"));

And this is the header file:

 #pragma once
 #include "GameFramework/Pawn.h"
 #include "MyPawn.generated.h"
 class CLIENTMESSAGE_API AMyPawn : public APawn
     void SetupInputComponent();
     void printMessage();
Product Version: Not Selected
more ▼

asked Nov 08 '14 at 03:33 PM in C++ Programming

avatar image

3 6 6 9

avatar image BaderThanBad Nov 08 '14 at 04:20 PM

Did you add in the Edit->Project Settings->Input->Action Mappings the printStuff and set it to the buttons you want it to register?

avatar image laserbeam897 Nov 08 '14 at 04:28 PM

yes i did.

avatar image BaderThanBad Nov 08 '14 at 04:23 PM

Also call Super::SetupInputComponent(); in the beginning of your setupinputcomponent function.

avatar image laserbeam897 Nov 08 '14 at 04:30 PM

my SetupInputComponent wasnt overridden from the base class , because when i did i got a build error saying that the base class did not contain a function named SetupInputComponent.

avatar image BaderThanBad Nov 08 '14 at 04:32 PM

Not sure but shouldn't this input handling be in a player controller? And if you move it there tag it as virtual void SetupInp....

avatar image BaderThanBad Nov 08 '14 at 04:36 PM

Sorry ignore this and try first setting your functions to public.

avatar image laserbeam897 Nov 08 '14 at 04:37 PM

That fixed it , thanks.

avatar image Tobias88 Mar 09 '15 at 09:05 PM

Same happened for me. The AGameController constructor is too early for registration, because the InputComponent was nullptr, because AActor::EnableInput(APlayerController* PlayerController) is not called. I tried that manually, now this is not throwing an exception, but did not work (4.7.2):

 class BUTTONFOOTBALL_API AGameController : public APlayerController
     AGameController(const FObjectInitializer& ObjectInitializer);
     virtual void SetupInputComponent() override;
     void OnFirePressed();


 AGameController::AGameController(const FObjectInitializer& ObjectInitializer)
     : Super(ObjectInitializer)
 void AGameController::OnFirePressed()
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("%s"), __FUNCTION__));
 void AGameController::SetupInputComponent()
     InputComponent->BindAction("F", IE_Pressed, this, &AGameController::OnFirePressed);

Any ideas?

(and how can set the syntax highlighting for this code?)

avatar image BaderThanBad Mar 11 '15 at 03:55 PM

Move it to BeginPlay instead of constructor perhaps.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

The constructor isn't the problem. I already tried the beginplay and the InputComponent was nullptr... If I call the hack(??) (AActor::EnableInput(this)), I got some assert and it did not response to my action

more ▼

answered Mar 11 '15 at 05:35 PM

avatar image

1 1 1

avatar image BaderThanBad Mar 11 '15 at 06:46 PM

Is that controller possessing or spawning a pawn? You should be feeding the input you get to a pawn you are controlling or referencing instead of calling that function.

avatar image BaderThanBad Mar 11 '15 at 06:54 PM

link text, read up a bit about pawns and controllers to get an idea of what is happening. I haven't looked it up but I believe you are referencing a non static function in a static way, ie what actor are you trying to enable input on, and what are you trying to do as a whole. There are many examples out there that can help you get started on setting up controllers.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question