x

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"

How do I set up input inside the PlayerController instead of the character?

I want to handle input inside a custom player controller class instead of my character's class. Do I have to cast? If yes the how? I tried searching everywhere but for some reason nothing helped.

Product Version: UE 4.17
Tags:
more ▼

asked Nov 07 '17 at 07:07 PM in C++ Programming

avatar image

Pencil Amazing
8 2 1 3

avatar image ImVawx ♦♦ STAFF Nov 07 '17 at 10:41 PM

You should be able to use the SetupInputComponent() function inside of the PlayerController class -- or YourPlayerController class, inherited from PlayerController.

If you look at the function, it creates a InputComponent that you can then use to bind input to.

There may be more to this step, such as making sure that the controller is the one accepting input, instead of the the Character. I am not 100% but I would start by looking at the player controller function and see if you can use it in a way you want.

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

1 answer: sort voted first

Inside your CustomCharacterController.h file, you need something like this:

 virtual void SetupInputComponent() override;

Then, in your cpp file:

 void ACustomCharacterController::SetupInputComponent()
 {
     Super::SetupInputComponent();
 
     InputComponent->BindAction("MyAction", IE_Pressed, this, &ACustomCharacterController::FunctionToCall);
 }

Then, just make sure the game's spawning your custom character controller for the player and not the default controller. That's usually set in the GameMode you're running.

more ▼

answered Nov 07 '17 at 11:26 PM

avatar image

Raap
1 1 1

(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