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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Binding Overlap delegate in UBoxComponent subclass

I'm new to c++ and can't quite get a handle on delegate binding. I'm trying to write a class derived from UBoxComponent that binds to the OnComponentBeginOverlap dynamic multicast delegate.

I also have a dynamic array of primitive components declared for this class. What I would like this component to do is maintain an index of any and all components from other actors it is overlapping with. Here's what I've got so far:

my h:

 #pragma once

 #include "Components/BoxComponent.h"
 #include "FloorSensor.generated.h"
 
 UCLASS()
 class MYPROJECT_API UFloorSensor : public UBoxComponent
 {
     GENERATED_BODY()
 
 public:
 
     UFloorSensor(const FObjectInitializer& ObjectInitializer);
     
     FComponentBeginOverlapSignature StartOverlappingDelegate;
     
     UFUNCTION()
     void StartOverlappingDelegate(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
     
     bool bIsOverlapping;
     
     // Stores overlapping components whose parent actor implements certain interface
     TArray<UPrimitiveComponent*> OverlappingComponents;
 };

my ccp:

 #include "MyProject.h"
 #include "FloorSensor.h"
 
 UFloorSensor::UFloorSensor(const FObjectInitializer& ObjectInitializer)
     : Super(ObjectInitializer)
 {
     
 }
 
 void UFloorSensor::StartOverlappingDelegate(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
 {
 
 }

I'm getting several errors:

error C2365: 'UFloorSensor::StartOverlappingDelegate' : redefinition; previous definition was 'data member'

error C2064: term does not evaluate to a function taking 5 arguments

I'd be hugely grateful for any help here.

Product Version: UE 4.7
Tags:
more ▼

asked May 17 '15 at 10:59 PM in C++ Programming

avatar image

jasputin
1 1 2 3

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

2 answers: sort voted first

Got it working pretty much by just leaving out the delegate type declaration (and getting the right delegate function signature. So now I really don't know where/how to use FComponentBeginOverlapSignature, but I'll open a separate question for that when the time comes.

Here's relevant code:

h:

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

ccp:

 // In constructor
 OnComponentBeginOverlap.AddDynamic(this, &UFloorSensor::StartOverlappingDelegate);

 // member function defintion
 void UFloorSensor::StartOverlappingDelegate(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
 {
     UE_LOG(LogTemp, Log, TEXT("Component started overlapping"));
 }

This is pretty intuitive and I would have done this first off if I hadn't read through all the delegates documentation.

more ▼

answered May 18 '15 at 10:53 PM

avatar image

jasputin
1 1 2 3

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

Hello, jasputin

The error occurs because you have the same name StartOverlappingDelegate for the variable and for the function.

Hoep this helped!

Cheers!

more ▼

answered May 18 '15 at 06:42 AM

avatar image

Andrii Melnyk
1.8k 60 19 112

avatar image jasputin May 18 '15 at 04:24 PM

Thanks for the reply Andrew. That makes sense. I guess I'm not sure what to do with the FComponentBeginOverlapSignature delegate type name in a derived class. Could you clue me in? I'm trying to follow the docs here (https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Delegates/index.html) but can't quite make sense of it.

(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