AddDynamic Problem

Looks like it is expecting a UPrimitiveComponent but you are trying to use a AActor.

Can you paste what is in your constructor?

I actually find it working when i renamed the function into “BeginOverlap”. I am kinda new to ue4 but it think this is silly since the funcion is not a primitive function of any base class (i guess) . So if i let the definition correct and refactor the name, it doesn’t work anymore. Why is that? Can’t i just call the function as i want?

I think it was “ProxSphereOverlap” or something like this. However i changed it many times and only with the name “BeginOverlap” it works. As i said if i change just the name of the function leaving the definition correct, it seems to not work anymore.

I think it was “ProxSphereOverlap” or something like this. However i changed it many times and only with the name “BeginOverlap” it works. As i said if i change just the name of the function leaving the definition correct, it seems not to work anymore.

That’s strange, maybe if you post your code it would help to figure out what the issue is.

Have you also tried deleting your Intermediate & Saved folders and building again?

I can’t manage to use AddDynamic in my constructor. It does not appear in the list and when i compile it, it says i need to define it and i get many errors.
What is this about?
Am i wrong to use it in the constructor?
Do i need to define it in some way?

I get this error:
Errore C2664 ‘void TBaseDynamicMulticastDelegate<FWeakObjectPtr,void,UPrimitiveComponent *,AActor *,UPrimitiveComponent *,int32,bool,const FHitResult &>::__Internal_AddDynamic(UserClass ,void (__cdecl ANPC:: )(UPrimitiveComponent *,AActor *,UPrimitiveComponent ,int32,bool,const FHitResult &),FName)’: cannot convert argument 2 from 'void (__cdecl ANPC:: )(AActor ,int32,bool,const FHitResult &)’ to 'void (__cdecl ANPC:: )(UPrimitiveComponent *,AActor *,UPrimitiveComponent *,int32,bool,const FHitResult &)’ GoldenEgg D:\Matteo\Progetti UE4\GoldenEgg 4.16\Source\GoldenEgg\NPC.cpp 18

The syntax for AddDynamic is as follows

OnComponentOverlap.AddDynamic(this, &ANPC::OnOverlapThing);

It looks like your issue is with the function that you are binding the delegate to. It is expecting the following function definition

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

Hopefully this helps!

What did you have the function named before?

Declaration:
UFUNCTION()
void BeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult);

Definition:
**void ANPC::BeginOverlap(UPrimitiveComponent * OverlappedComponent, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
GEngine->AddOnScreenDebugMessage(-1, 2, FColor::White, npcMessage);
}

Binding:
proxSphere->OnComponentBeginOverlap.AddDynamic(this, &ANPC::BeginOverlap);

I am new to UE4, how do i delete those files you talk about?
PS: i posted only these lines of code cause the whole code required too many characters and i couldn’t post it.

Thanks for helping ! :slight_smile:

I know this is old, but the issue is still valid.

Closing down UE4 and launching it again seems to fix the problem. I’m guessing its a caching issue. Annoying, but great to have found a consistent solution.

Edit: issue still valid as of 4.19.2