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"

Recieving Null Pointer in-between methods

I have a damage interface that takes in a pointer to an actor, damage and a float for force: UFUNCTION(BlueprintNativeEvent) void RecieveDamage(AActor* otherActor, float damage, float force);

When called from any class to my player class, the function works and I receive no issues. However, when all of the same classes call on my enemy class the enemy class otherActor is received as a nullptr and crashes the game. I am not calling them any differently and I cannot figure out why the enemy class is only receiving null pointers from the method call.

Here is the Player Function:

 void ACutiePlayer_Character::RecieveDamage_Implementation(AActor* otherActor, float damage, float force)
 {
 //otherActor isValid here
     if (!Invincible)
     {
 
         //Reduce Health
         Health -= damage;
         IsDamaged = true;
         Invincible = true;
         this->DisableInput(PlayerCon);
 
         GetCharacterMovement()->StopMovementImmediately();
 
         FVector LineOfContact = otherActor->GetActorLocation() - this->GetActorLocation();
         LineOfContact.Normalize();
         FVector LaunchForce = LineOfContact * -force;
         GetCharacterMovement()->AddImpulse(LaunchForce, true);
     }
 }


And Here is the enemy function:

 void AEnemy_Basic::RecieveDamage_Implementation(AActor* otherActor, float damage, float force)
 {
 //otherActor is not valid here
     //Reduce Health
     Health -= damage;
     IsDamaged = true;
 
     //Call Method to disrupt movement.
     GetCharacterMovement()->StopMovementImmediately();
 
     if (otherActor != nullptr) //Not Passing
     {
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("ActorExists!")));
     }
     if (IsValid(otherActor)) //Not Passing
     {
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("ActorExists!")));
         FVector LineOfContact = otherActor->GetActorLocation() - this->GetActorLocation();
         LineOfContact.Normalize();  //Crashes Engine
         FVector LaunchForce = LineOfContact * -force;
         GetCharacterMovement()->AddImpulse(LaunchForce, true);
     }
     else // Always Passing
     {
         GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Does not Exist!")));
     }
 }

Product Version: UE 4.21
Tags:
more ▼

asked Mar 03 '19 at 10:45 PM in C++ Programming

avatar image

alekroks
1 1

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

1 answer: sort voted first

I found out what it was,

turns out I was calling the recievedamage function in a blueprint sub-class and it was overriding the function without passing the otherActor parameter.

more ▼

answered Mar 09 '19 at 10:25 PM

avatar image

alekroks
1 1

(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