Download

AddDynamic undefined?

I’m attempting to recreate something I made in blueprints in C++ and I haven’t hit a roadblock until this part.

I’ve found one page in the documentation that has exactly what I wanted to do in code…


Sphere1->OnComponentBeginOverlap.AddDynamic(this, &ALightSwitchBoth::OnOverlap);

However when I try to implement that in my project I’m finding that AddDynamic does not exist. I’m guessing the implementation changed between when the documentation page was written and now? So how would I implement something like the above?

AddDynamic its a macro that calls the funcion __Internal_AddDynamic, i have 4.5 and the the define AddDynamic still exist. What you have above its should works, try to compile it

I get the following when trying to compile with that. (But it seems to define it when I compile which answers that first question)



1>F:\Unreal Projects\Area53\Source\Area53\Private\pickup_AmmoCrate.cpp(13): error C2664: 'void TBaseDynamicMulticastDelegate_FiveParams<void,AActor *,UPrimitiveComponent *,int32,bool,const FHitResult &,FWeakObjectPtr>::__Internal_AddDynamic<Apickup_AmmoCrate>(UserClass *,void (__cdecl Apickup_AmmoCrate::* )(Param1Type,Param2Type,Param3Type,Param4Type,Param5Type),const FString &)' : cannot convert argument 2 from 'void (__cdecl Apickup_AmmoCrate::* )(AActor *,UPrimitiveComponent *,int32)' to 'void (__cdecl Apickup_AmmoCrate::* )(Param1Type,Param2Type,Param3Type,Param4Type,Param5Type)'
1>          with
1>          
1>              UserClass=Apickup_AmmoCrate
1>  ,            Param1Type=AActor *
1>  ,            Param2Type=UPrimitiveComponent *
1>  ,            Param3Type=int32
1>  ,            Param4Type=bool
1>  ,            Param5Type=const FHitResult &
1>          ]
1>          and
1>          
1>              Param1Type=AActor *
1>  ,            Param2Type=UPrimitiveComponent *
1>  ,            Param3Type=int32
1>  ,            Param4Type=bool
1>  ,            Param5Type=const FHitResult &
1>          ]
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


Here is the line the error is referencing:



TouchSphere->OnComponentBeginOverlap.AddDynamic(this, &Apickup_AmmoCrate::OnPickup);


Aha figured it out!

So following the documentation on the function part of it turned out to be the cause. After looking in the Blueprint implementation it turns I needed to change it from:



void Apickup_AmmoCrate::OnPickup(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)


to



void Apickup_AmmoCrate::OnPickup(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool FromSweep, const FHitResult& SweepResult)


with the two extra parameters.