unreal-engine4unrealscript

Unreal Engine 4, AddDynamic is not working if being called from constructor


I'm a begginer, trying to finish a simple UE4 C++ tutorial: https://www.raywenderlich.com/185-unreal-engine-4-c-tutorial#toc-anchor-001 At the point where you're additing OnActorBeginOverlap.AddDynamic(this, &ABaseCoin::OnOverlap) into ABaseCoin constructor in order to handle the event, it's just not working. the OnOverlap function is not being called when I overlap this actor( But if I put OnActorBeginOverlap.AddDynamic into ABaseCoin::BeginPlay everything is working. Please, help, who knows something about this problem


Solution

  • Problems arise when using .AddDynamic in the constructor now. It can also cause Blueprint corruption.

    Put every constructor .AddDynamic in PostInitializeComponents() or BeginPlay()