I’m trying to bind my function to OnTakePointDamage, but it acts unstable. I couldn’t get it to work yesterday but managed to do it eventually, however today it doesn’t work again. Am I missing something? Also hitting play for the first time in the session triggers a breakpoint in VS in some internal script and UE log in shows this: Ensure condition failed InvocationList[ CurFunctionIndex ] != InDelegate. But I can just press resume and this error won’t show up until the next session in Unreal
.h
UCLASS()
class MYPROJ_API CPP_EnemyBase : public ACharacter
{
GENERATED_BODY()
public:
ACPP_EnemyBase();
protected:
virtual void BeginPlay() override;
...
UFUNCTION()
void HandlePointDamage(AActor* DamagedActor, float Damage, class AController* InstigatedBy, FVector HitLocation, class UPrimitiveComponent* FHitComponent, FName BoneName, FVector ShotFromDirection, const class UDamageType* DamageType, AActor* DamageCauser); //The function I want to bind
public:
virtual void Tick(float DeltaTime) override;
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
Why do use GetOwner() ?
Your class is derived from ACharacter, which is derived from APawn, which is derived from AActor, which has the OnTakePointDamage delegate declared in it. So you have the access to it directly. I guess GetOwner() returns something you don’t need. Try removing it maybe?
Tuerer is right. I think this error means you are binding a delegate twice, which you might be doing with GetOwner. I remember something very similar, didn’t check the source to be sure.
*Edit, yep, that’s it.
ScriptDelegates.h line 556:
So, I got rid of GetOwner(), but the error still pops up and I’m sure I don’t have other binds. It doesn’t seem to cause any problems, Tuerer’s solution worked, but should I be worried about it?
I fugered out what causes the error, but it’s the bind from another class. I recently moved the binding there from initialization to BeginPlay, I reverted the change and now it doesn’t throw errors
I’m confused, I’ve read that I shouldn’t put bindings in initialization because it might be corrupted in the process (which happened with OnTakePointDamage bind from the first post initially)
// Sets default values
CPP_Class::CPP_Class()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Verify same function isn't already bound (or throw error)
I have no other explanation than just to believe the source code comment, I doubt that somehow a previously made binding has survived a change in source code but if there is no other place you are making a binding I can’t think of any.
You could go into VS and set breakpoints to read when / where it was previously set from .