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"

4.3 Add Dynamic On Component Overlap error

The new 4.3 update has been causing some issues with my code. I have an actor which consists of a UBoxComponent that should call another function on component overlap. It was working fine in Version 4.2 when I used AddDynamic to delegate from OnComponentOverlap to the function I wanted it to call, but when I converted the project to Version 4.3 I got compiler error C2664:

'void TMulticastScriptDelegate::Add(const TScriptDelegate &)' : cannot convert argument 1 from 'void (__cdecl ALevelChangeDetection:: )(AActor ,UPrimitiveComponent *,int32)' to 'const TScriptDelegate &'

Does anyone have an idea what might be causing this, or a better way to call a function on component overlap? I didn't see anything in the release notes that looked relevant. I also tried pasting the code into a new 4.3 project in case the conversion process was the problem, but I still got the same error.

Here is the header file:

 #pragma once
 
 #include "GameFramework/Actor.h"
 #include "LevelChangeDetection.generated.h"
 
 UCLASS()
 class MYPROJECT_API ALevelChangeDetection : public AActor
 {
     GENERATED_UCLASS_BODY()
 
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "CollisionBox")
     TSubobjectPtr<UBoxComponent> CollisionBox;
 
     UFUNCTION()
     void OnOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
     
 };


and the source file:

 #include "MyProject.h"
 #include "LevelChangeDetection.h"
 
 
 ALevelChangeDetection::ALevelChangeDetection(const class FPostConstructInitializeProperties& PCIP)
     : Super(PCIP)
 {
     CollisionBox = PCIP.CreateAbstractDefaultSubobject<UBoxComponent>(this, TEXT("CollisionBox"));
     RootComponent = CollisionBox;
     CollisionBox->OnComponentBeginOverlap.AddDynamic(this, &ALevelChangeDetection::OnOverlap); 
 }
 
 void ALevelChangeDetection::OnOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
 {
 //do stuff
 }
 



Product Version: Not Selected
Tags:
more ▼

asked Jul 18 '14 at 03:25 AM in C++ Programming

avatar image

pagancyc
135 17 13 23

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

1 answer: sort voted first

Hi PaganCYC,

It seems that the new 4.3 update brought new signatures for the overlap functionality.

I've fixed this by using the delegate for the begin overlap signature (that's outlined in PrimitiveComponent.h by the DECLARE_DYNAMIC_MULTICAST_DELEGATE_FiveParams macro, here) and should give you an Overlap function declaration that looks like:

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

If you're ever going to use the end overlap, it uses a different signature, so use this function declaration instead:

 void OnEndOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

This should fix your compiler errors :)

EDIT: Also (for other people reading this), if your overlap does not work, make sure to add [YourGameName]_API to your class declaration, like so:

 class YOURGAMENAME_API UYourComponent : public USphereComponent

more ▼

answered Jul 18 '14 at 01:40 PM

avatar image

OrganicHumans
86 1 5 6

avatar image pagancyc Jul 18 '14 at 02:28 PM

Hey OrganicHumans,

I tried out your suggestion and it appears to have solved the problem. Thanks so much for your help!

avatar image OrganicHumans Jul 18 '14 at 10:05 PM

Awesome, no problem! Glad I could be of help :)

avatar image Daveoh Jul 23 '14 at 11:44 AM

Worked for me too! I was using the LightSwitchCodeOnly code from this which doesn't work in 4.3: https://docs.unrealengine.com/latest/INT/Gameplay/ClassCreation/CodeOnly/index.html

avatar image OrganicHumans Jul 25 '14 at 01:10 AM

Awesome Daveoh, glad to hear it helped :)

avatar image Spaehling Jul 25 '14 at 08:32 PM

It would be really great if you could post an example cpp code that actually works with this fix.

Since this is part of a tutorial problem its hard to figure out how to implement your fix in the code for an beginner like myself.

It would be so helpful to me and maybe other beginners to get this tutorial actually fixed Thanks.

avatar image CHADALAK1 Aug 17 '14 at 01:39 AM

I agree with Spaehling

But yet, let me get this straight. So you're saying that the OnComponentBeginOverlap stuff is replaced with a function called OnBeginOverlap as well as OnEndOverlap???

avatar image CHADALAK1 Aug 18 '14 at 12:59 AM

Answering my own commented question. I understand completely... basicaly it's saying for the AddDynamic overlap to work, it has to have 5 paramters.

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

because it used to be like this

 void OnBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);


but it's like the one on top instead.... thanks for everthing :)

avatar image MitaGames Sep 13 '14 at 02:39 PM

Thanks, worked for me too! This is my header file code:

 // Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
 #pragma once
 
 #include "GameFramework/Actor.h"
 #include "LightSwitchCodeOnly.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class THIRDPERSONLIGHT442_API ALightSwitchCodeOnly : public AActor
 {
     GENERATED_UCLASS_BODY()
 
     /** point light component */
     UPROPERTY(VisibleAnywhere, Category = "Switch Components")
     TSubobjectPtr<class UPointLightComponent> PointLight1;
 
     /** sphere component */
     UPROPERTY(VisibleAnywhere, Category = "Switch Components")
         TSubobjectPtr<class USphereComponent> Sphere1;
 
     /** called when something overlaps the sphere component */
     UFUNCTION()
         void OnBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
     UFUNCTION()
         void OnEndOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
     /** the desired intensity for the light */
     UPROPERTY(VisibleAnywhere, Category = "Switch Variables")
         float DesiredIntensity;
 };
 

   
avatar image MitaGames Sep 13 '14 at 02:41 PM

And cpp file: // Copyright 1998-2014 Epic Games, Inc. All Rights Reserved. #include "thirdpersonlight442.h" #include "LightSwitchCodeOnly.h"

 ALightSwitchCodeOnly::ALightSwitchCodeOnly(const class FPostConstructInitializeProperties& PCIP)
     : Super(PCIP)
 {
     DesiredIntensity = 3000.0f;
 
     PointLight1 = PCIP.CreateDefaultSubobject<UPointLightComponent>(this, "PointLight1");
     PointLight1->Intensity = DesiredIntensity;
     PointLight1->bVisible = true;
     RootComponent = PointLight1;
 
     Sphere1 = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("Sphere1"));
     Sphere1->InitSphereRadius(250.0f);
     Sphere1->AttachParent = RootComponent;
 
     Sphere1->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchCodeOnly::OnBeginOverlap);
         // set up a notification for when this component overlaps something
     Sphere1->OnComponentEndOverlap.AddDynamic(this, &ALightSwitchCodeOnly::OnEndOverlap);
 }
 
 
 void ALightSwitchCodeOnly::OnBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
 {
     if (OtherActor && (OtherActor != this) && OtherComp)
     {
         PointLight1->ToggleVisibility();
     }
 }
 
 void ALightSwitchCodeOnly::OnEndOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
 {
     if (OtherActor && (OtherActor != this) && OtherComp)
     {
         PointLight1->ToggleVisibility();
     }
 }
 
(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