How can I call a BlueprintImplementableEvent in C++?

So I’ve made custom events like this:

UFUNCTION(BlueprintImplementableEvent)
void ExecuteAbility(ACharacter* C);

I can see this event in Blueprint just fine. I call it from another C++ class, inside of a function like this:

currentAbility->ExecuteAbility(this);

Everything compiles fine, but in Blueprint the event never gets called.

Am I doing it wrong? I’ve looked for answers but in everything I find people seem to be able to just call them and they work.

#Something to Try

Try writing a wrapper like this

//ability class
void YourAbilityClass::CallBPEvent(ACharacter* C)
{
  this->ExecuteAbility(C);
}

and call this wrapper from your character class

ability->CallBPEvent(this);

Let us know if that changes anything

If it does NOT changing anything then that is actually good news and the problem is a simpler issue

if it DOES work, then Epic needs to look at this

#Something Else To Try

Try removing the ACharacter* parameter and just pass nothing or an integer to see if that changes behavior

Rama

Thank you so much for the reply. The wrapper didn’t work for me, I got the same result. I started thinking that maybe the wrapper was never being called so I used an OnScreenDebug. Here is what I have right now.

UFUNCTION(BlueprintImplementableEvent)
void NotifyExecuteAbility();

void AAbility::ExecuteAbility(ACharacter* C){

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("ExecuteAbility"));

this->NotifyExecuteAbility();

}

So I’m not making use of the *ACharacter parameter right now. The OnScreenDebugMessage shows on my screen, so it gets called, but the event doesn’t fire in Blueprint.

I think I found the problem. I tried calling a custom event in my character class and that worked. So the problem is that I’m not referencing the correct ability correctly.

So I have an array of Abilities in my Character class.

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Ability)
AAbility* AbilityArray[4];

Then I have an AAbility variable that holds the value of the current ability.

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Ability)
AAbility* currentAbility;

Then to call an ability I do this

void AMonsterCharacter::CallAbility(int abilityNum){

currentAbility = AbilityArray[abilityNum];
if (currentAbility)
	ChargeAbility();

}

ChargeAbility() then calls currentAbility->ChargeAbility(this); Which is a wrapper in my Ability class for a notification, this->NotifyChargeAbility();

I know ChargeAbility gets called because of an OnScreenDebugMessage, so I’m assuming that the event NotifyChargeAbility is also called. The problem is that my currentAbility pointer isn’t pointing to the right Ability instance.

The way I set up my AbilityArray is in BeginPlay I do this:

void AMonsterCharacter::BeginPlay(){

Super::BeginPlay();

AbilityArray[0] = GWorld->SpawnActor<AAbility>(AAbility::StaticClass());
    AbilityArray[1] = GWorld->SpawnActor<AAbility>(AAbility::StaticClass());

}

This works fine, the problem is that I want to make Blueprints based on my Ability class and then put those in my AbilityArray.

The way I’ve done this is in my Character Blueprint, in the BeginPlay event, after calling the super, I have this:

You can ignore the Set BP ones, but the SetAbility ones are where the problem might be.

SetAbility 1 - 4 are functions in my Character class.

void AMonsterCharacter::SetAbility1(AAbility* A){

AbilityArray[0] = A;
AbilityArray[0]->AbilityOwner = this;

}

So in the blueprint I spawn another blueprint based on Ability. Then I try to put that into the parameter for SetAbility which should then take this Ability based blueprint and store it in the array, replacing what was there before. This doesn’t seem to be working though. I don’t get any errors, but I think that’s why I’m not getting the event to fire in my blueprint.

Also I’m not sure if in my SetAbility functions I should delete the previous Ability stored in my Ability Array before setting it to something else. I tried destroying the previous value but that always causes my game to crash when I hit play.

#Wiki Example

Try copying over my wiki example in a new class context (get away from the current class situation, so you can step back and get perspective)

Rama