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"

OnHit is not working c++

I have been creating a level in where a door opens when the player character walks into it. I have set up a OnHit for the door, but when the character walks into it; it doesn't respond.

Here is my OnHit code, my character is called theWolfCharacter

 void APushDoor::OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
 {    
     if (OtherActor->GetName().Contains(TEXT("character"), ESearchCase::IgnoreCase, ESearchDir::FromStart))
     {
         if (GEngine)
         {
             GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("shot hit asteroid"));
         }
     }
     
     doorHit = true;
         if (GEngine)
         {
             GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("door hit"));
         }
 }
Product Version: UE 4.8
Tags:
more ▼

asked May 13 '16 at 05:55 PM in C++ Programming

avatar image

isaidnomods
1 1 2 1

avatar image zimzimdz May 13 '16 at 06:00 PM

What does your .h look like ?

avatar image isaidnomods May 13 '16 at 09:15 PM

Sorry about the delay, I'll give my whole .cpp and .h files using paste bin since there are too many characters for a response :S

.cpp -> http://pastebin.com/Ki7yhuH6

.h -> http://pastebin.com/hT9dUzwa

Thank you in advance :)

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

2 answers: sort voted first

Your OnHit function will not be called because it is not bound to anything, you should rather override the NotifyHit function and do your logic in it. "Simulation Generates Hit Events" should not be neccessary as the character movement will trigger it anyways.

more ▼

answered May 14 '16 at 12:28 PM

avatar image

Fluppi393
457 36 33 54

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

"Simulation Generates Hit Events" set to true under the collision tab in blueprint. Also, it might be a good idea to have a delegate going on the constructor.

more ▼

answered May 14 '16 at 12:12 PM

avatar image

Zarkopafilis
335 33 26 45

(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