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"

Character overlap box with other actors

I want to attach a box component to the front of my character that calls a function when it overlaps with a custom interactable class derived from actor. How would I go about doing this? So far I have this in my character cpp file...

 InteractableCollisionShape = CreateDefaultSubobject<UBoxComponent>(TEXT("interactable collision box"));
 InteractableCollisionShape->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
 InteractableCollisionShape->SetCollisionResponseToAllChannels(ECR_Ignore);
 InteractableCollisionShape->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
 InteractableCollisionShape->bGenerateOverlapEvents = true;
 InteractableCollisionShape->OnComponentBeginOverlap.AddDynamic(this, &AMyCharacter::onInteractableHit);
 InteractableCollisionShape->SetupAttachment(GetMesh());

This is stuff I've gathered from different tutorials, but its mostly just me blindly throwing darts at a dart board. I dont know what I need to get rid of or change. Any help would be greatly appreciated.

(Its important the collision box is attached to the character and not the object so that the function it is only called when the player is facing that object, not just in its area. Also a line trace doesn't work because its too finicky with different sized and shaped objects.)

Product Version: UE 4.19
Tags:
more ▼

asked Jun 10 '18 at 05:13 PM in C++ Programming

avatar image

FishMob
5 3

avatar image ZeroParadigm Jun 11 '18 at 10:08 PM

Hi @FishMob , can you describe the behavior you are seeing versus what you are expecting? I dont see anything inherently wrong with the code you posted. The other actor needs to have "generate iverlap events " set to true as well.

Note that any overlap will throw the OnActorBeginOverlap event, so you will have to use the halfspace test between your character orientation and the initial contact to determine if you are looking at the object.

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

0 answers: sort voted first
Be the first one to answer this question
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