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"

Ways to generate OnOverlap in an Actor class?

Hi!

I read different question and answers related why Components OverlapsEvent not generated, but no one solved my problem.

In C++ I try to register a delegate function to my StaticMeshComponent of my actor. On first look it compiles but OnOverlaps events are never generated if the ball and the paddle overlaps.

Header file:

 #pragma once
 
 #include "GameFramework/Actor.h"
 #include "BallActor.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class VOID_API ABallActor : public AActor
 {
     GENERATED_UCLASS_BODY()
 
     UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Ball)
     TSubobjectPtr<UStaticMeshComponent> BallStaticMesh;
 
     void OnConstruction(const FTransform &Transform) override;
     void Tick(float DeltaSeconds) override;
 
     void OnBeginOverlap(AActor *OtherActor, UPrimitiveComponent *OtherComponent, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);
 };


Source file:

 #include "Void.h"
 #include "BallActor.h"
 
 
 ABallActor::ABallActor(const class FPostConstructInitializeProperties& PCIP)
     : Super(PCIP)
 {
     BallStaticMesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("BallStaticMesh"));
     RootComponent = BallStaticMesh;
 
     static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMeshObj(TEXT("StaticMesh'/Game/Meshes/Ball/Ball.Ball'"));
     BallStaticMesh->StaticMesh = StaticMeshObj.Object;
 
     // register OverlapEvents
     BallStaticMesh->bGenerateOverlapEvents = true;
     TScriptDelegate<FWeakObjectPtr> delegateFunction;
     delegateFunction.BindUFunction(this, "OnBeginOverlap");
     BallStaticMesh->OnComponentBeginOverlap.Add(delegateFunction);
 
     // activate tick
     PrimaryActorTick.bCanEverTick = true;
     PrimaryActorTick.bStartWithTickEnabled = true;
     PrimaryActorTick.bAllowTickOnDedicatedServer = true;
 }
 
 void ABallActor::OnConstruction(const FTransform &Transform)
 {
     Super::OnConstruction(Transform);
 
     BallStaticMesh->SetMobility(EComponentMobility::Movable);
 }
 
 void ABallActor::Tick(float DeltaSeconds)
 {
     Super::Tick(DeltaSeconds);
 }
 
 void ABallActor::OnBeginOverlap(AActor *OtherActor, UPrimitiveComponent *OtherComponent, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
 {
     if (GEngine)
     {
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("In OnOverlap!"));
     }
 }


The UStaticMesh which is attached to the UStaticMeshComponent has sphere collision generated in the editor: SphereCollision

The paddle obj has a box collsion generated in the editor too. In the blueprints of the paddle and ball is "Generate Overlap Events" set to true. BP_ball

Product Version: Not Selected
Tags:
ballcollision.png (43.9 kB)
ball_bp.png (18.3 kB)
more ▼

asked Sep 08 '14 at 09:55 PM in C++ Programming

avatar image

ThePathfinder
140 6 6 18

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

1 answer: sort voted first

Okay, I solved my error. facepalm

Forgot the UFUNCTION() before OnBeginOverlap

 UFUNCTION()
     void OnBeginOverlap(AActor *OtherActor, UPrimitiveComponent *OtherComponent, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);
more ▼

answered Sep 08 '14 at 10:20 PM

avatar image

ThePathfinder
140 6 6 18

(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