AddDynamic cannot bind an included function

If AddDynamic is used to bind an included function, it will throw the error ‘no instance of function template"FComponentHitSignature::__Internal_AddDynamic" matches the argument list’.

boundBox->OnComponentHit.AddDynamic(this, &UJumperMovement::OnCollide);

This is the code I attempted to use in my AJumper class. The “OnCollide” function was included from UJumperMovement, and I was trying to figure out why that error was being thrown despite the correct signature. Upon moving the “OnCollide” function to my AJumper class, and adjusting the AddDynamic parameters to match, no errors were thrown.

I can’t imagine this is intended, as this is very inconvenient behavior.

Hi ,

I am not sure I completely understand the setup that you are using. Is AJumper a child class of UJumperMovement? Would you be able to provide a simplified version of the code in both classes so I can get a better idea of how they are related?

Sorry about the delayed response, but…
I was about to attach related code before I realized I’ve lost it now.
But, AJumper wasn’t a child class of UJumperMovement. I seriously don’t know why I said “inherited” instead of “included.” Must’ve been pretty tired.

AJumper was an actor, while UJumperMovement was a pawn movement component, if I recall. Including the latter and attempting to use AddDynamic to bind its “OnCollide” function yielded an error identical to that of an incorrect function signature, which confused me for a while. Eventually, I moved that exact function, with no changes, to the AJumper class and AddDynamic worked fine.

Hello quiesciens,

Sorry for not getting back to you sooner. I believe the issue that you were running into was that the compiler was trying to resolve the function in the AJumper class, and could not find a function that matched the signature in the UJumperComponent class because the binding was being made in the AJumper class instead of the UJumperComponent class. The AddDynamic() function needs a specific instance of a class in which to look for the specified function to run. In the example line that you provided, this tells the function that the &UJumperMovement::OnCollide is located in the current AJumper7 class.

Since UJumperMovement is included by AJumper (I am guessing that you added a UJumperMovement component to the AJumper class), you can tell AddDynamic() to look for the function in the component attached to the current class by using the following line:

BoundBox->OnComponentHit.AddDynamic(JumperComponent, &UJumperComponent::OnCollide);

That should allow the compiler to properly resolve the function.