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"

.h file includes:

 #include "CoreMinimal.h"
 #include "GameFramework/Actor.h"
 #include "PTZRCharacter.h"
 #include "PTZRPortal.generated.h"

.cpp file function snippet:

 void APTZRPortal::TeleportActor(AActor* ActorToTeleport)
 {
     if (ActorToTeleport == nullptr || Target == nullptr)
     {
         return;
     }
 
     //-------------------------------
     //Retrieve and save Player Velocity
     //(from the Movement Component)
     //-------------------------------
     FVector SavedVelocity = FVector::ZeroVector;
     APTZRCharacter* EC = nullptr;
 
     if (ActorToTeleport->IsA(APTZRCharacter::StaticClass()))
     {
         EC = Cast<APTZRCharacter>(ActorToTeleport);
 
         SavedVelocity = EC->GetCharacterMovement()->Velocity;
     }

Above is part of my code and the problem I am having is that VS is underlining the "EC" variable in the "SavedVelocity" definiton (last line) in red, telling me that "Pointer to incomplete class type is not allowed". I am quite new to C++ in Unreal and I have no idea why I am getting this error. I have searched around on Google for this issue and all the answers basically tell them that they forgot to include a certain engine component. However I can't think of what I could have possibly forgotten to include here. "EC" here is just a pointer to the "PTZRCharacter" class (a custom character class I made) and I have indeed included the header file of that class in my header file.

I can't possibly think of anything else I need to include. Any ideas?

Product Version: UE 4.22
Tags:
more ▼

asked Apr 06 '19 at 06:34 PM in C++ Programming

avatar image

Schytheron
68 1 6 9

avatar image GarnerP57 Apr 06 '19 at 06:48 PM

Can it compile?

avatar image Schytheron Apr 06 '19 at 06:52 PM

@GarnerP57 Nope, it doesn't compile.

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

1 answer: sort voted first

Normally when declaring a class variable in a header file it is done by what is known as "Forward Declaration".

MyActor.h

 #pragma once
 
 #include "CoreMinimal.h"
 
 class ADifferentActor; //Forward declaration of ADifferentActor
 
 UCLASS()
 class AMyActor : public AActor
 {
     GENERATED_BODY()
 public:
     ADifferentActor* MyDifferentActorPointer ;
 };


MyActor.cpp

 #include "MyActor.h"
 #include "ADifferentActor.h" //Completed Declaration of ADifferentActor
     
 //Now when you have Set MyDifferentActorPointer to point at an instance of ADifferentActor you can begin to use the functions in it

So make sure that you completed the declaration and not only made a forward declaration to the APTZRCharacter class. You always want to include as few things as possible in a header file so it is lighter when other classes need to include it. When declaring a pointer variable it doesn't need to know what the class consist of and can be handled as any other generic pointer UNTIL you want to use the type the pointer points to.

more ▼

answered Apr 06 '19 at 07:47 PM

avatar image

GarnerP57
1k 3 4 8

avatar image Schytheron Apr 06 '19 at 08:28 PM

Ah, thanks! It worked.

(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