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"

Begin Overlap in C++

Hi community

I am trying to make an actor be able to fire off an ActorBeginOverlap event in c++. I keep getting errors and due to my inexperience with c++, I am unable to identify what needs fixing and how to fix it.

My code is below:

My c++ file

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "PlatformTrigger.h"
 #include "Components/BoxComponent.h"
 
 // Sets default values
 APlatformTrigger::APlatformTrigger()
 {
      // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
 
     TriggerVolume = CreateDefaultSubobject<UBoxComponent>(FName("TriggerVolume"));
     
     if (!ensure(TriggerVolume != nullptr)) return;
 
     RootComponent = TriggerVolume;
 
     TriggerVolume->OnComponentBeginOverlap.AddDynamic(this, &APlatformTrigger::OnOverlapBegin);
 
 
 }
 
 // Called when the game starts or when spawned
 void APlatformTrigger::BeginPlay()
 {
 
 
     Super::BeginPlay();
     
 }
 
 // Called every frame
 void APlatformTrigger::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
 
 }
 
 void APlatformTrigger::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
 {
     UE_LOG(LogTemp, Warning, TEXT("Activated"));
 
 }


And my header file

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #pragma once
 
 #include "CoreMinimal.h"
 #include "GameFramework/Actor.h"
 #include "PlatformTrigger.generated.h"
 
 UCLASS()
 class PUZZLEPLATFORM_API APlatformTrigger : public AActor
 {
     GENERATED_BODY()
     
 public:    
     // Sets default values for this actor's properties
     APlatformTrigger();
 
 protected:
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
 
 public:    
     // Called every frame
     virtual void Tick(float DeltaTime) override;
 
 private:
     UPROPERTY(VisibleAnywhere)
     class UBoxComponent* TriggerVolume;
 
     UFUNCTION()
     {
         void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
     };


Product Version: UE 4.19
Tags:
more ▼

asked May 14 '18 at 08:02 PM in C++ Programming

avatar image

AgentArachnid66
7 3 4 11

avatar image Janyx May 15 '18 at 04:29 AM

press post the errors you are getting, so we can help.

avatar image AgentArachnid66 May 15 '18 at 01:27 PM

Alright. I have added the screenshots of the errors

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first
 .h
 
 class UBoxComponent* Box
 
 UFUNCTION()
 void OnBoxBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
 
 .cpp
  
 Box=CreateDefaultSubobject<UBoxComponent>(TEXT("Box"));
 
 Box->OnComponentBeginOverlap.AddDynamic(this, &AYourClass::OnBoxBeginOverlap);

if it does not work you need to first reload visual studio from editor (file menu).

restarting your project can always make everything work better :))

more ▼

answered May 17 '18 at 10:56 AM

avatar image

saeedc
2.3k 72 40 105

avatar image AgentArachnid66 May 21 '18 at 12:17 PM

This worked. Thank you so much

(comments are locked)
10|2000 characters needed characters left

Try declaring your overlap function like this:

          UFUNCTION()
          void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
 

It can't find the definition of OnOverlapBegin I believe it's because you have placed curly braces around the definition, I have never seen that syntax before so I am assuming that's the problem.

more ▼

answered May 15 '18 at 03:17 PM

avatar image

Janyx
482 66 64 211

avatar image AgentArachnid66 May 15 '18 at 05:56 PM

I did this in the header file and it gave me the error "Function definition for "OnOverlapBegin" not found" in the header file And the c++ file was "declaration is incompatible"

avatar image Janyx May 17 '18 at 04:27 AM

You are gonna have to send me the errors again and all the the output.

avatar image Janyx May 18 '18 at 04:25 AM

I just noticed this, remove the semi-colon on the end of line 39 and give it a try

avatar image AgentArachnid66 May 21 '18 at 12:17 PM

That was one of the issues I had and after removing the semi colon and the resolved answer, it worked

(comments are locked)
10|2000 characters needed characters left

I would have posted the errors I am getting, if I could have uploaded them at the time of uploading this question

Here is the log message

alt text

alt text

more ▼

answered May 15 '18 at 11:22 AM

avatar image

AgentArachnid66
7 3 4 11

(comments are locked)
10|2000 characters needed characters left
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