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"

identifier is undefined

i'm trying to cast my aicharacter to hit.getactor but i keep getting this error identifier "Hit" is undefined and for my if statment if my hit.getactor is true then i can apply damage (damageamount) and i get the same error and i'm apply damage to my linetrace


 void AHordeCharacter::OnFire()
     AAI_Character* character = Cast<AAI_Character>(Hit.GetActor);
     FHitResult Hit(ForceInit);
     FVector start = FP_Gun->GetForwardVector();
     FVector End = start + (FP_Gun->GetForwardVector()* 700.f);
     FCollisionQueryParams CollisionParams;
     FVector Start = FP_Gun->GetComponentLocation();
     DrawDebugLine(GetWorld(), Start, End, FColor::Green, true, 2.f, false, 4.f);
     GetWorld()->LineTraceSingleByChannel(Hit, start, End, ECC_WorldDynamic, CollisionParams);
     if (Hit.GetActor)

AI character.h health = 5.f; damageamount = 2.f;

 void AAI_Character::damage(float damageamount)
     health = health - damageamount;

Product Version: Not Selected
more ▼

asked Apr 21 '19 at 08:00 AM in C++ Programming

avatar image

11 3 8 9

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

1 answer: sort voted first

Hit is indeed undefined at line 6. You need to prepare the Hit struct before you use it like with the Line Trace.

more ▼

answered Apr 21 '19 at 08:13 AM

avatar image

936 3 4 8

avatar image Eatbootyeveryday Apr 22 '19 at 12:21 AM

thank you the hit is identified but how do i fix the problem with the damageamount i got my AI character .h file in there but it keeps coming up

avatar image GarnerP57 Apr 22 '19 at 08:23 AM

If you fix Hit.GetActor then the Character will no longer be NULL and in turn that should fix the call to damage.

avatar image Eatbootyeveryday Apr 23 '19 at 02:42 AM

thank you everything works but my damageamount still has the error

avatar image GarnerP57 Apr 23 '19 at 08:19 AM

Please be specific. What is the error?

(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