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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Best way to bind input to component?

Hi there guys. Currently i'm trying to modularize all that i can via components for later use, and one of those things that i'm wanting to modularize is the ability to interact with others "interactable" objects.

Right now the component will iterate on every Overlaping actor on the Owner and check whether they implement the IInteractableInterface (if they do or not respond to the Interact message). All goes well until this point but the moment that i press the Interact key ("E" default), i need the InteractorComponent to call the Interact method on itself.

Now my question goes like this, what is the best way to bind the input to that component? I have been thinking on this scenarios:

1) The Actor Owner should bind the action manually on the input component via

 InputComponent->BindAction("Interact", IE_Pressed, 
     this->InteractorComponentPointer, &UInteractorComponent::Interact);

But this breaks the advantage of being plug and play, also i would need to know that the Interact method exists on my component (knowing too much of the component).

2) Pass the InputComponent and the Event name to the component and bind the action on the initialize component

 //On InitializeComponent on the interactor

I think that this would be good, i only would need to configure the component on creation and it would be set, but a drawback would be that it needs an input component and that breaks modularization a little

3) I have read that delegates are the way to go but i don't know how they could be applied here

Any suggestions?


Product Version: UE 4.10
more ▼

asked Jun 16 '16 at 04:53 AM in C++ Programming

avatar image

277 11 20 33

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

1 answer: sort voted first

Hello, I know the post is old, but I came across your doubt trying to do exactly the same. I was able to solve it as follows.

In the component header:

 ACharacter* OwnerCharacter;

In the component source:

 void UCharacterInteractionComponent::BeginPlay() {
     OwnerCharacter = Cast<ACharacter>(GetOwner());
     OwnerCharacter->InputComponent->BindAction("Interact", IE_Pressed, this, &UCharacterInteractionComponent::Interact);
more ▼

answered Mar 06 '17 at 12:56 AM

avatar image

Tiago Papile
26 2 3

avatar image ndelchen Feb 08 '18 at 11:15 AM

Hi, is this still working in 4.18? InputComponent seems to be NULL on BeginPlay().

avatar image Gnurr Feb 08 '18 at 12:12 PM

hmm, the InputComponent being NULL on BeginPlay sounds wrong, are you sure you are dealing with a possessed character/pawn and are not overwriting the InputComponent somehow yourself?

anyways, just tested it and it should be working in 4.18

avatar image 6r0m Mar 26 '19 at 09:22 AM

perfectly working with blueprint pawn (4.20), thank you!

(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