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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Why is UE4 crashing when calling interface function

Hi Everyone,

I am not sure what I am doing wrong here. When I try to make a call to the function AffectHealth, I get a crash. I have tried casting the object using Cast (As seen below) and InterfaceCast<>.

This is where the function where the crash occurs:

 void AWeapon::NotifyActorBeginOverlap(AActor* OtherActor)
 {
     IDamageable* damageableActor = Cast<IDamageable>(OtherActor);
 
     // Check if this actor is damageable
     if (damageableActor)
     {
              // THIS IS WHERE THE CRASH Happens
         damageableActor->AffectHealth();
     }
 }

This is the interface defined in C++:

 UINTERFACE(BlueprintType)
 class HSROUGE_API UDamageable : public UInterface
 {
     GENERATED_BODY()
 
 };
 
 class HSROUGE_API IDamageable
 {
     GENERATED_BODY()
 
 public:
 
     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "DamageSystem")
     void AffectHealth();
 };

Base character class implementing the Interface: UCLASS() class ABaseCharacter : public ACharacter, public IDamageable { . . . UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "DamageSystem") void AffectHealth();

     virtual void AffectHealth_Implementation();
 .
 .
 .
 }

 void ABaseCharacter::AffectHealth_Implementation()
 {
     UE_LOG(LogTemp, Warning, TEXT("I %s health is affected From BaseCharacter Class"), *this->GetName());
 }


Product Version: UE 4.15
Tags:
more ▼

asked Apr 10 '17 at 11:57 PM in C++ Programming

avatar image

Impulse21
141 4 10 14

avatar image Impulse21 Apr 11 '17 at 12:15 AM

Sorry it appears the last section got messed up

 UCLASS()
 class ABaseCharacter : public ACharacter, public IDamageable
 {
     GENERATED_BODY()
 
 public:
     // Sets default values for this character's properties
     ABaseCharacter();
 
 
     UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "DamageSystem")
     void AffectHealth();
 
     virtual void AffectHealth_Implementation();
 }
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

My apologies, I have found the answer in the UE4 Interfaces in C++ Located here

Here is my fixed code:

  void AWeapon::NotifyActorBeginOverlap(AActor* OtherActor)
  {
      IDamageable* damageableActor = Cast<IDamageable>(OtherActor);
  
      // Check if this actor is damageable
      if (damageableActor)
      {
          IDamageable::Execute_AffectHealth(OtherActor);
      }
  }

more ▼

answered Apr 11 '17 at 12:20 AM

avatar image

Impulse21
141 4 10 14

(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