Unrecognized Type - Cannt find Structure from Include

While trying to structure and sort my code files and includes, I encountered a problem I don’t know how to fix.

I made an example Project, so the files will be small.

The class MyActor can spawn Objects form type “ObjectA” and ObjectA contains the structure “FObjectAData” to hold some data.

The file “TestProject.h” is unedited.

MyActor.cpp

#include "TestProject.h"
#include "MyActor.h"

#include "ObjectA.h"

AMyActor::AMyActor()
{
	PrimaryActorTick.bCanEverTick = true;
}

void AMyActor::BeginPlay()
{
	Super::BeginPlay();
}

void AMyActor::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
}

void AMyActor::MakeObjectA(FObjectAData data)
{
   // code to spawn an Actor from type ObjectA
}

(we can assume that the code for spawning is working)

MyActor.h

#pragma once

#include "GameFramework/Actor.h"
#include "MyActor.generated.h"

class AObjectA;
struct FObjectAData;

UCLASS()
class TESTPROJECT_API AMyActor : public AActor
{
	GENERATED_BODY()
	
public:	
	AMyActor();
	virtual void BeginPlay() override;
	virtual void Tick( float DeltaSeconds ) override;

   UFUNCTION(BlueprintCallable, Category = "myActor")
   void MakeObjectA(FObjectAData data);
	
};

ObjectA.cpp

#include "TestProject.h"
#include "ObjectA.h"

#include "MyActor.h"

AObjectA::AObjectA()
{
	PrimaryActorTick.bCanEverTick = true;

   this->actorRef = nullptr;
}

void AObjectA::BeginPlay()
{
	Super::BeginPlay();
}

void AObjectA::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
}

void AObjectA::SetActorRef(AMyActor *inActorRef)
{
   this->actorRef = inActorRef;
}

ObjectA.h

#pragma once

#include "GameFramework/Actor.h"
#include "ObjectA.generated.h"

class AMyActor;

USTRUCT(BlueprintType)
struct FObjectAData
{
   GENERATED_BODY()

public:      
   UPROPERTY(BlueprintReadWrite, Category = "object A")
   float data1;
   UPROPERTY(BlueprintReadWrite, Category = "object A")
   float data2;
   UPROPERTY(BlueprintReadWrite, Category = "object A")
   float data3;
};


UCLASS()
class TESTPROJECT_API AObjectA : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AObjectA();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

   UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "object A")
   AMyActor *actorRef;
   UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "object A")
   FObjectAData data;

   UFUNCTION(BlueprintCallable, Category = "object A")
   void SetActorRef(AMyActor *inActorRef);

};

When I want to compile I get this error:

Basically both classes need to know each other. So I made them visible with forward declerations. I don’t want to include files itself in the Header.

Hi TheRealSpook ,

You forward declared the struct AObjectA which you are using as a reference. That would have worked if you used that struct as a pointer in the header. Unfortunately you need to include the header were you declared the struct as otherwise the compiler doesn’t know what to allocate.

Cheers,

You can totally use structs as pointers, it just depends on the use case.

You tried this?

UFUNCTION(BlueprintCallable, Category = "myActor")
void MakeObjectA(FObjectAData* data);

Thanks, I tried to use the struct as Pointer, but still the same error.

As far as I know structs are normally not used as Pointer, if you see the FVector.

Yes I did try this. I gives me the same error.