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"

[C++] Is there a way to get input from actor that isn a pawn/character ?

Is there a way to get input from actor that isn a pawn/character ? Like you have a component wich acts as your input but is just an component and not an pawn/character?

Product Version: Not Selected
Tags:
more ▼

asked Mar 03 '15 at 12:39 PM in C++ Programming

avatar image

Gunschlinger
111 16 23 41

avatar image kbrizov Mar 15 '17 at 03:47 PM

I realize this is a very old question and it still doesn't have an answer, so I am going to answer with a question. Did you find a way?

avatar image Podgyhodgy Apr 25 '17 at 10:01 AM

I have just posted an answer to this. Maybe it will help you.

avatar image Shinpansen May 01 '17 at 07:20 PM

Oh my god ! You're my hero just right now. I spent the entire day trying to do that correctly.

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

1 answer: sort voted first

Here is my solution to this problem - basically you make your own function to setup the bindings. This example has two action mappings in Project Settings - One called ZoomIn and one called ZoomOut. All it does at the moment is write a message the Output log window when each event occurs but you can expand it to any number of bindings and put what you like in the delegate functions. The header file

 UCLASS()
 class CUSTOMBP01_API AInput : public AActor
 {
     GENERATED_BODY()
     
 public:    
     // Sets default values for this actor's properties
     AInput();
     //two functions to be called when a key is pressed
     void ZoomIn();
     void ZoomOut();
     //a boolean to be set/reset just to record the last key event state
     bool bZoomingIn;
     /** Component that handles input for this actor, if input is enabled. */
     //UPROPERTY()
     //    class UInputComponent* InputComponent;  //already defined in scope AActor
 
 protected:
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
 
 public:    
     // Called every frame
     virtual void Tick(float DeltaTime) override;
     // Called to bind functionality to input
     void SetupMyPlayerInputComponent(UInputComponent* myInputComponent);
     //take away 'class' identifier used in unreal pawnwithcamera example
     //change name to eliminate warning message :-
     
 };

The cpp file:-

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "customBP01.h"
 #include "Input.h"
 //#include "KeyPressing.h"   //no such file or directory
 
 //General Log used only for display of messages to Output Log
 DEFINE_LOG_CATEGORY(YourLog);
 
 // Sets default values
 AInput::AInput()
 {
      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
 
 }
 
 // Called when the game starts or when spawned
 void AInput::BeginPlay()
 {
     //Run the BeginPlay function of this class' parent class - do I need this
     //What does it actually do.
     Super::BeginPlay();
     //the most recently enabled actor will be at top of input stack
     //see unreal docs on input for details of stack priority
     //enableinput takes a player controller 
     EnableInput(GetWorld()->GetFirstPlayerController());
     //the enable input used here means i dont have to enable auto receive input in the editor window
     UInputComponent* myInputComp = this->InputComponent;  //InputComponent variable is from AActor.h
     //check that it is valid before calling
     //i.e. not null.  
     if (myInputComp)
     {
         SetupMyPlayerInputComponent(myInputComp);
     }
     
 }
 
 // Called every frame
 void AInput::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
     //"MyCharacter's Bool is %s"
     //UE_LOG(YourLog, Warning, TEXT("AInput bZoomingIn is %s"), (this->bZoomingIn ? TEXT("True") : TEXT("False")));
     //UE_LOG(YourLog, Warning, TEXT("hasbindings is %s"), (this->InputComponent->HasBindings() ? TEXT("True") : TEXT("False")));
 
     if (bZoomingIn)
     {
         //UE_LOG(YourLog, Warning, TEXT("true really true"));
     }
     else
     {
         //UE_LOG(YourLog, Warning, TEXT("false really false"));
     }
 
 
 
 
 
 }
 
 void AInput::ZoomIn()
 {
     UE_LOG(YourLog, Warning, TEXT("zoomin called"));
     bZoomingIn = true;
 }
 
 void AInput::ZoomOut()
 {
     UE_LOG(YourLog, Warning, TEXT("zoomout called"));
     bZoomingIn = false;
 }
 
 
 
 //finally got this being called when enabled auto receive input.
 void AInput::SetupMyPlayerInputComponent( UInputComponent* myInputComponent) {
     UE_LOG(YourLog, Warning, TEXT("SETUP PLAYER INPUT COMPONENT"));
     //Super::SetupPlayerInputComponent(InputComponent);   //Another experimental thing 
 
     //Hook up events for "ZoomIn" and "ZoomOut"
     myInputComponent->BindAction("ZoomIn", IE_Pressed, this, &AInput::ZoomIn);
     myInputComponent->BindAction("ZoomOut", IE_Released, this, &AInput::ZoomOut);
 
 }


I have put in a lot of comments so you should be able to work out what is going on.

hope this helps.

more ▼

answered Apr 25 '17 at 10:00 AM

avatar image

Podgyhodgy
251 4 7 13

avatar image kbrizov Apr 25 '17 at 03:11 PM

Thanks for spending the time.

avatar image ireChae Apr 25 '18 at 03:25 AM

Thanks you! I have had same problems. I'm gonna try this

(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