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"

[SOLVED]How to add a delegate to the Begin/End ComponentOverlap?

This is my header

// Fill out your copyright notice in the Description page of Project Settings.

 #pragma once
 
 #include "CoreMinimal.h"
 #include "GameFramework/Character.h"
 #include "FPS_Character.generated.h"
 
 class UCameraComponent;
 
 UCLASS()
 class BASIC_SHOOTER_01_API AFPS_Character : public ACharacter
 {
     GENERATED_BODY()
 
 public:
     // Sets default values for this character's properties
     AFPS_Character();
 
 protected:
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
 
 public:    
     // Called every frame
     virtual void Tick(float DeltaTime) override;
 
     // Called to bind functionality to input
     virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
 
     
 private:
     bool isTouchingGround = false;
 
 private:
     UCameraComponent* ptrCamera = nullptr;
 
 private:
     void Jump();
 
     UFUNCTION()
     void OnCollisionEnter
                     (
                         const FOverlapInfo& OtherOverlap,
                         bool bDoNotifies
                     );
 
     UFUNCTION()
     void OnCollisionExit
                     (
                         const FOverlapInfo& OtherOverlap,
                         bool bDoNotifies,
                         bool bSkipNotifySelf
                     );
 };
 

This is my CPP file

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "FPS_Character.h"
 #include "Camera/CameraComponent.h"
 #include "Engine.h"
 #include "Components/CapsuleComponent.h"
 
 
 // Sets default values
 AFPS_Character::AFPS_Character() :
     ptrCamera { CreateDefaultSubobject<UCameraComponent>(TEXT("FPS_camera")) }
 {
      // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
 
     ptrCamera->SetupAttachment(this->GetCapsuleComponent());
     ptrCamera->RelativeLocation = FVector(-39.56f, 1.75f, 64.f);
 
     this->GetCapsuleComponent()->BeginComponentOverlap.AddDynamic(this, &AFPS_Character::OnCollisionExit);
     this->GetCapsuleComponent()->EndComponentOverlap.AddDynamic(this, &AFPS_Character::OnCollisionEnter);
 }
 
 // Called when the game starts or when spawned
 void AFPS_Character::BeginPlay()
 {
     Super::BeginPlay();
 }
 
 // Called every frame
 void AFPS_Character::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
 
 }
 
 // Called to bind functionality to input
 void AFPS_Character::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
 {
     Super::SetupPlayerInputComponent(PlayerInputComponent);
 
 }
 
 void AFPS_Character::Jump()
 {
 }
 
 void AFPS_Character::OnCollisionEnter
 (
     const FOverlapInfo& OtherOverlap, 
     bool bDoNotifies
 )
 
 {
     if (OtherOverlap.OverlapInfo.GetActor() != this)
     {
         GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, FString::Printf(TEXT("You collided with: %s"), OtherOverlap.OverlapInfo.GetActor()->GetName()));
     }
 }
 
 void AFPS_Character::OnCollisionExit
 (
     const FOverlapInfo& OtherOverlap, 
     bool bDoNotifies, 
     bool bSkipNotifySelf
 )
 
 {
     if (OtherOverlap.OverlapInfo.GetActor() != this)
     {
         GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, FString::Printf(TEXT("You uncollided with: %s"), OtherOverlap.OverlapInfo.GetActor()->GetName()));
     }
 }
 


When I compile it says: "Unrecognized type 'FOverlapInfo' - type must be a UCLASS, USTRUCT or UENUM".

How can I fix this?

Product Version: UE 4.20
Tags:
more ▼

asked Sep 27 '18 at 08:26 PM in C++ Programming

avatar image

BALKAN BANDIT
12 1 1 5

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

1 answer: sort voted first

from PrimitiveComponent.h

 /** Delegate for notification of start of overlap with a specific component */
 DECLARE_DYNAMIC_MULTICAST_DELEGATE_SixParams( FComponentBeginOverlapSignature, UPrimitiveComponent*, OverlappedComponent, AActor*, OtherActor, UPrimitiveComponent*, OtherComp, int32, OtherBodyIndex, bool, bFromSweep, const FHitResult &, SweepResult);

 /** Delegate for notification of end of overlap with a specific component */
 DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams( FComponentEndOverlapSignature, UPrimitiveComponent*, OverlappedComponent, AActor*, OtherActor, UPrimitiveComponent*, OtherComp, int32, OtherBodyIndex);

Those are the function signatures your functions need. I would also recommend binding the functions during begin play but it may work in the constructor.

more ▼

answered Sep 28 '18 at 08:53 AM

avatar image

HarryHighDef
1.3k 1 14 16

avatar image Firefly74 Sep 28 '18 at 10:02 AM

that's the correct answer, and yep, i definitely recommend to bind delegates in BeginPlay instead if ctor :)

avatar image BALKAN BANDIT Sep 28 '18 at 11:55 AM

Yep! Thank you for helping me, it works! But I wonder why is it bad to bind them in the c-tor, is it unreliable?

avatar image Firefly74 Sep 28 '18 at 12:23 PM

it's more of a good habits, Because it would only work for component created in c++ ctor ( so for a char it's good ), all other components ( the one you add in bps ) are not loaded yet, in begin play you are sure it's all good ( or in ComponentsPostInitialize)

(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