[help] Generated .cpp files don't recognize the struct from my .h


	USTRUCT(BlueprintType)
	struct FMazeRow
	{
		GENERATED_USTRUCT_BODY()

		//or could be using a simple data type instead of a Data Unit Struct
		UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Maze Array")
		TArray<bool> col;

		FMazeRow(){}
	};

	USTRUCT(BlueprintType)
	struct FMazeArray
	{
		GENERATED_USTRUCT_BODY()

		UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Maze Array")
		TArray<FMazeRow> row;

		FMazeArray(){}
	};

This is part of my .h file for a new Maze actor I’ve created, for my first game, MazeGame.

When I try to compile it tells me that in MazeGame.generated.cpp, FMazeRow is not a class or namespace.

Since MazeGame.generated.cpp includes MazeGame.h I tried including Maze.h in MazeGame.h but it did not make the generated .ccp to find FMazeRow

This is all based off of the 2d array described [Replicating a 2D dynamic array - C++ - Epic Developer Community Forums]here](Replicating a 2D dynamic array - C++ - Epic Developer Community Forums)

Try using the API export macro between the struct keyword and the struct name. You can see an example of the macro if you create a class using the class wizard. It will end up looking something like



struct GAMEMODULENAME_API FMazeRow
{
    ....
};


Just replace the GAMEMODULENAME part of the macro with your project name.


class MAZEGAME_API AMaze : public AActor

Is the beginning of my class, leading me to think you are suggesting


	USTRUCT(BlueprintType)
	struct MAZEGAME_API FMazeRow
	{
		GENERATED_USTRUCT_BODY()

		//or could be using a simple data type instead of a Data Unit Struct
		UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Maze Array")
		TArray<bool> col;

		FMazeRow(){}
	};

	USTRUCT(BlueprintType)
	struct MAZEGAME_API FMazeArray
	{
		GENERATED_USTRUCT_BODY()

		UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Maze Array")
		TArray<FMazeRow> row;

		FMazeArray(){}
	};

If so this did not work. I still have


E:\Documents\Unreal Projects\MazeGame\Intermediate\Build\Win64\Inc\MazeGame\MazeGame.generated.cpp(11): error C2653: 'FMazeRow' : is not a class or namespace name

as the first of many errors. Would it help to post the rest of the class, even though it is almost entirely generated code? Or maybe to post the whole error list?

Yeah that’s what I was suggesting, I know I’ve seen this before I just can’t remember how I fixed it. There’s no point posting the generated code since you can’t edit it anyway, the source of the problem will be in another file, either the header or MazeGame.cpp.

Do you have the structs in their own header file or in with something else? If there in their own header file that you created manually make sure you have #include “HeaderFileName.generated.h” as the last include. Make sure you include “HeaderFileName.h” in any .cpp files using the struct as well. You probably know all that.

Can you post both the header file for the structs and the normal MazGame.cpp file? (not the generated one)

This is Maze.h, the header file containing the structs. (I assume this is what you mean by “the header file for the structs”)


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

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

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

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

	AMaze(int height, int width);

	USTRUCT(BlueprintType)
	struct MAZEGAME_API FMazeRow
	{
		GENERATED_USTRUCT_BODY()

		//or could be using a simple data type instead of a Data Unit Struct
		UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Maze Array")
		TArray<bool> col;

		FMazeRow(){}
	};

	USTRUCT(BlueprintType)
	struct MAZEGAME_API FMazeArray
	{
		GENERATED_USTRUCT_BODY()

		UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Maze Array")
		TArray<FMazeRow> row;

		FMazeArray(){}
	};
};


Here is the MazeGame.cpp (I haven’t touched this at all, I added the class to what is originally a blueprint third-person default game)


// Fill out your copyright notice in the Description page of Project Settings.

#include "MazeGame.h"

IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, MazeGame, "MazeGame" );


I don’t use either of the structs anywhere yet, I haven’t written any code yet really because making the 2D array was the first thing I tried to do.

I tried adding Include “MazeGame.generated.h” to the MazeGame.h since that wasn’t in there but it says it doesn’t exist, and since I didn’t make this file I would assume Unreal made the file correctly to start with.

Just for the fun of it:
MazeGame.h


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Engine.h"


Maze.cpp



// Fill out your copyright notice in the Description page of Project Settings.

#include "MazeGame.h"
#include "Maze.h"


// Sets default values
AMaze::AMaze()
{
	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = false;
}

AMaze::AMaze(int height, int width)
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = false;
}

// Called when the game starts or when spawned
void AMaze::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AMaze::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

}


The unreal reflection system doesn’t support nested structs or classes. Move your USTRUCTS to the top of the file above the UCLASS, and you should be fine.

Oh, cool. It’s working now and I’m pretty sure I’ve read that somewhere in the bajillion tutorials I’ve been through but couldn’t figure it out from the error message. Thank you so much kamrann and karltheawesome for the help.