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"

Component overlap delegates not working

I'm trying to set up a drop object that the player can pick up if he enters a trigger component of the drop. This should be fairly easy to manage with only C++ code, the class is created as normal but for some reason I can't add a dynamic to OnComponentBeginOverlap. Here's my code:

Header

 UCLASS()
 class PROJECTWAIFU_API ADrop : public AActor
 {
     GENERATED_BODY()
     
 public:    
     // Sets default values for this actor's properties
     ADrop();
 
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
     
     // Called every frame
     virtual void Tick( float DeltaSeconds ) override;
 
     UPROPERTY(VisibleAnywhere)
     USphereComponent* grabBox;
     
     UFUNCTION()
     void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
 };

.cpp

 ADrop::ADrop()
 {
     grabBox = CreateDefaultSubobject<USphereComponent>(TEXT("Grab collision"));
     grabBox->SetSphereRadius(200.0f);
     grabBox->bGenerateOverlapEvents = true;
     grabBox->OnComponentBeginOverlap.AddDynamic(this, &ADrop::OnOverlapBegin);
 }
 
 void ADrop::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
 {
     // ...
 }

AddDynamic seems to be working but OnOverlapBegin() will never be called. Are there any other properties I may be missing?

Product Version: UE 4.12
Tags:
more ▼

asked Nov 09 '16 at 04:24 AM in C++ Programming

avatar image

Herreteman
5 2 5 6

avatar image ballerbaer Apr 03 '17 at 04:58 PM

Have you created your Blueprint before implementing the overlap event? If yes, you have to re-create your Blueprint for some reason: https://answers.unrealengine.com/questions/32320/oncomponentbeginoverlap-not-working.html

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

1 answer: sort voted first

I bind my overlap event delegates this way and it works flawlessly

 ADrop::ADrop()
  {
     grabBox = CreateDefaultSubobject<USphereComponent>(TEXT("Grab collision"));
     grabBox->SetSphereRadius(200.0f);
     grabBox->bGenerateOverlapEvents = true;
     
     FScriptDelegate BeginOverlapDelegate;
     BeginOverlapDelegate.BindUFunction(this, FName("OnOverlapBegin"));
     grabBox->OnComponentBeginOverlap.AddUnique(BeginOverlapDelegate);
  }
  
  void ADrop::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
  {
     GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Cyan, TEXT("PAAAAW OVERLAP"));
  }

Remember to add UFUNCTION() macro to OnOverlapBegin method.

more ▼

answered Apr 03 '17 at 06:29 PM

avatar image

Sveitar
1k 8 24 28

(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