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"

Cannot bind OnComponentHit

I am having a bit of a problem binding OnComponentHit to one of my capsule components. The problem is that the implementation worked before and when I cleaned up the class (moving some variables around to make it more readable), it just stopped working. Not sure whether that is actually the cause, but thought I should mention. Anyways, as for the code:

.h

 UFUNCTION()
     void OnFrontalCapsuleHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);

.cpp

 FrontalHitCheckCapsule->SetNotifyRigidBodyCollision(true);
 FrontalHitCheckCapsule->OnComponentHit.AddDynamic(this, &MyCharacter::OnFrontalCapsuleHit);

 void MyCharacter::OnFrontalCapsuleHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
 {
     UE_LOG(AnyLog, Log, TEXT("Got a hit"));
 }

I have doublechecked the capsule components in the blueprint, and all of the relevant ones had the NotifyRigidBodyCollision set to true. I also tried binding it to the default CapsuleComponent instead of the one I added, but no luck there either. Would love to get this solved, as not being able to assign an OnHit kinda messes with the gameplay I was planning on implementing.

Product Version: UE 4.11
Tags:
more ▼

asked May 26 '16 at 09:38 AM in C++ Programming

avatar image

cridia
815 30 26 105

avatar image cridia May 27 '16 at 12:32 AM

I have done some more experiments, and the problem is becoming weirder and weirder.

I have done 3 checks. -First I checked whether the object was bound using IsBound(), which returned true. -Secondly I checked more specifically using Contains(this, "OnFrontalCapsuleHit"), which also returned true. -Lastly I checked which objects were bound by using GetAllObjects(), and confirmed that it was bound only to my character.

Despite all this, the function is just not being called on an actual hit.

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

1 answer: sort voted first

OK, I hope this helps you.

This is the code I'm using in my project:

 PickupCollisionSphere->OnComponentHit.AddDynamic(this, &APickup::HitTheGround);
 
 void APickup::HitTheGround(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)

I was staring at the blueprint thingie for OnComponentHit and noticed that there's a 'Hit Component' in front of the 'Other Actor' and your parameters didn't include it. Could this be the cause of your problems?

I'm using 4.12 btw.

more ▼

answered Jul 11 '16 at 10:53 AM

avatar image

TempDN3
49 1 2 8

avatar image cridia Sep 13 '16 at 06:00 AM

Sorry, that wasn't really my problem. With 4.12 they changed the signature a bit, adding an additional argument. If my problem was that of a lacking argument in my OnHit function, it would never have compiled to begin with. The problem here was that even though OnHit was bound and everything, it never actually fired.

The problem solved itself when I switched engines, so I still don't know exactly what was wrong there.

(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