x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: Not Selected
Tags:
more ▼

asked Apr 26 '14 at 12:57 PM in C++ Programming

avatar image

pzea
71 8 10 16

avatar image pzea Apr 26 '14 at 11:15 PM

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:

alt text

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;

}

avatar image pzea Apr 26 '14 at 11:15 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

more ▼

answered Apr 26 '14 at 02:37 PM

avatar image

Rama
10.6k 446 343 1085

avatar image pzea Apr 26 '14 at 10:33 PM

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.

avatar image Rama Apr 28 '14 at 08:33 PM

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)

https://wiki.unrealengine.com/Blueprints,_Empower_Your_Entire_Team_With_BlueprintImplementableEvent

Rama

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question