Bindings set in the constructor are not being removed from the event system once modified in the constructor

UPDATED INFORMATION
This bug occurs when setting an event in the constructor, it is not being removed from the event system if it is modified after the fact, instead the OLD binding remains as well as the new one being added instead of replaced.

ORIGINAL POST - Some information may no longer be correct

The bug is either allowing you to bind events in the constructor or that binding something in it’s place wont work in the constructor.

Here’s the relevant steps to what I’ve done:

  1. Subclassed Character.h and called it Player_Character
  2. Declared the function in Player_Character.h : void PathDetect_Add(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
  3. Defined the function in Player_Character.cpp to print to UE_LOG
  4. Bound the function in the constructor SplineDetectCapsule->OnComponentBeginOverlap.AddDynamic(this, &APlayer_Character::PathDetect_Add);
  5. Tested in game - works, the UE_LOG is printed successfully when an overlap occurs
  6. Went back to my Player_Character.h and refactored PathDetect_AddPathDetect_Enter
  7. Confirmed everything updated, it did
  8. Tested in game, does not work, the UE_LOG is not printed
  9. Moved the AddDynamic() from the constructor to BeginPlay()
  10. Tested in game, works, the UE_LOG is printed

Between every attempt I closed the editor and did a build solution.

The objects are spawned when the game runs, they aren’t pre-existing.

Hello ,

I tried following your steps to reproduce this problem but even once I got to step 5, the overlap wouldn’t trigger the function. To ensure I’m not missing out on anything, I used the Third Person Template to recreate this and added your function / declaration. I then tried adding the following line to the constructor and (after it didn’t work) to BeginPlay.

GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &AMyProject6Character::PathDetect_Add);

To ensure that overlap events were firing, I set an overlap on the other object in blueprints and it worked without fail. As a note, they are both being spawned at runtime via the Level Blueprint. Are you seeing any behavior similar to this?

We haven’t heard from you in a while, . Are you still experiencing this issue? If so, could you take a look at my previous comment and see where I may be going wrong in my attempt to reproduce the problem? In the meantime, I’ll be marking this issue as resolved for tracking purposes.

I have clearer information now, sorry for the delay.

This occurred again down the line. I did in the constructor OnActorBeginOverlap.AddDynamic and it was fine, later on I decided to change it to OnActorEndOverlap.AddDynamic - same function etc

It was then being called on both begin and end overlap, meaning that … and this is the summarized bug report:

Bindings set in the constructor are not being removed from the event system once modified in the constructor

(I have modified the post title and added the summary to the top)

Would it be possible for you to provide a sample project where you have this bug occurring? The issue I’m running into is that the delegates never seem to be bind properly if the binding is located in the constructor, which is pivotal to your issue. I do have a couple other questions that could have an impact. Are you using a source built version of the engine or a version downloaded from the Epic Games Launcher? Are you running the editor in debug via Visual Studio when these issues occur?

I’m using the version from Epic Games Launcher, when these issues occur I’m running “Development Editor”.

I will prepare a sample project and test also in “DebugGame Editor”. I’ve moved away from using Development Editor in favour of DebugGame Editor almost entirely now anyway.

The only thing is I have a lot on my plate, I’d like to say I’ll get it to you within 7 days and hope that I don’t forget. :slight_smile: Feel free to give me a reminder if I don’t.

Hey ,

I’m going to leave this here as resolved for tracking reasons until you’re able to test what we discussed. Whenever you’re ready, leave another comment here and the post will open.