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"

Pointer to incomplete class type is not allowed

I've been trying to make a simple game where the player hits a target and is then rewarded with points.

void ABullet::OnBulletHit(AActor* SelfActor, AActor* OtherActor, FVector NormalImpulse, const FHitResult & Hit) { if (ATarget Target = Cast(OtherActor)) { if (ASomeGameMode GM = Cast(GetWorld()->GetAuthGameMode())) { GM->OnTargetHit(); } }

}

the error appears at the "GetWorld" section of the code i have included all the necessary files for this to work, yet it doesn't

Product Version: UE 4.22
Tags:
more ▼

asked May 09 '19 at 04:40 PM in C++ Programming

avatar image

N3on_Spectre
3 1 1

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

1 answer: sort voted first

assuming you have included all the necessary includes

 #include "Engine/World.h"
 #include "SomeGameMode.h"
 #include "Target.h"
 #include "GameFramework/Actor.h" (probably included from your Bullet.h file)
 #include "GameFramework/GameModeBase.h" (probably included from your SomeGameMode.h file)

shouldn't it be something like this?

 void ABullet::OnBulletHit(AActor* SelfActor, AActor* OtherActor, FVector NormalImpulse, const FHitResult & Hit) 
 { 
     if (auto* Target = Cast<ATarget>(OtherActor))
     {
         if (auto* GM = Cast<ASomeGameMode>(GetWorld()->GetAuthGameMode()))
         {
             GM->OnTargetHit();
         }
     }
 }
more ▼

answered May 09 '19 at 07:37 PM

avatar image

Lardo Deepdelver
956 6 4 6

avatar image N3on_Spectre May 10 '19 at 10:02 AM

This fixed it, thank you very much

avatar image Lardo Deepdelver May 10 '19 at 11:35 AM

Glad to help, could you pls accept the answer I'm a little OCD about not closed questions :P

(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