Struct Class Not Recognized

You have a cyclic include. CraftingStation.h includes GameplayController.h, which in turn includes CraftingStation.h.

Either break up your files so you can access the types you need without this cycle, or see if you can use a forward declaration of your type instead (you can if you only need a pointer or reference to your type in your header).

Just realized this is my Source code :smiley: Hope the tutorial is going well

What includes do Interactable.h, CraftingGameGameMode.h, and CraftingGameCharacter.h have?

As someone very new to programming in C++ and in UE4, I have come across a bit of a hurdle that I cannot seem to find the answer to.

I have header file that references a struct defined in another header file. For some reason, even though the the headers reference each other in the “#include” section, for some reason when I try to call the struct in an array, I get the following output error in VS.

1>------ Rebuild All started: Project: CraftingGame, Configuration: Development_Editor x64 ------
1>  Cleaning CraftingGameEditor Binaries...
1>  Creating makefile for CraftingGameEditor (no existing makefile)
1>  Performing full C++ include scan (no include cache file)
1>  Parsing headers for CraftingGameEditor
1>    Running UnrealHeaderTool "F:\Epic Games\Unreal Projects\CraftingGame\CraftingGame.uproject" "F:\Epic Games\Unreal Projects\CraftingGame\Intermediate\Build\Win64\CraftingGameEditor\Development\CraftingGameEditor.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -installed
1>F:/Epic Games/Unreal Projects/CraftingGame/Source/CraftingGame/GameplayController.h(36): error : Unrecognized type 'FCraftingInfo' - type must be a UCLASS, USTRUCT or UENUM
1>EXEC : error : UnrealHeaderTool failed for target 'CraftingGameEditor' (platform: Win64, module info: F:\Epic Games\Unreal Projects\CraftingGame\Intermediate\Build\Win64\CraftingGameEditor\Development\CraftingGameEditor.uhtmanifest, exit code: OtherCompilationError (5)).
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(42,5): error MSB3073: The command ""F:\Epic Games\UE_4.15\Engine\Build\BatchFiles\Rebuild.bat" CraftingGameEditor Win64 Development "F:\Epic Games\Unreal Projects\CraftingGame\CraftingGame.uproject" -waitmutex" exited with code -1.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Here are my header files:

CraftingStation.h

#pragma once

#include "Interactable.h"
#include "GameplayController.h"
#include "Engine/DataTable.h"
#include "CraftingStation.generated.h"

/**
 * 
 */


UCLASS()
class CRAFTINGGAME_API ACraftingStation : public AInteractable
{
	GENERATED_BODY()

public:
	ACraftingStation();

	UPROPERTY(EditAnywhere)
		UStaticMeshComponent* StationMesh;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		FName ItemID;

protected:




};

USTRUCT(BlueprintType)
struct FCraftingInfo
{
	GENERATED_BODY()

public:

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		FName ComponentID;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		FName ProductID;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		bool bDestroyComponentA;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		bool bDestroyComponentB;



};


USTRUCT(BlueprintType)
struct FCraftingInventory
{
	GENERATED_BODY()

public:



};

And GameplayController.h, where the error is generated from.

#pragma once

#include "GameFramework/PlayerController.h"
#include "CraftingStation.h"
#include "CraftingGameGameMode.h"
#include "CraftingGameCharacter.h"
#include "GameplayController.generated.h"

/**
 * 
 */
UCLASS()
class CRAFTINGGAME_API AGameplayController : public APlayerController
{
	GENERATED_BODY()
	
public:


	//Reloads inventory after crafting
	UFUNCTION(BlueprintImplementableEvent)
	void ReloadInventory();

	UFUNCTION(BlueprintCallable, Category = "Utilities")
	void AddItemToInventoryByID(FName ID);

	UFUNCTION(BlueprintCallable, Category = "Utilities")
	void AddItemToStationInventoryByID(FName ID);

	UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
	TArray<FInventoryItem> Inventory;
	
	UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
	TArray<FCraftingInfo> CraftingInventory;

	//the interactable the player is looking at. If none, nullptr
	
	UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
	class AInteractable* CurrentInteractable;

	

protected:

	virtual void SetupInputComponent() override;
	
	void OnInteract();

	void StopInteract();
	
};

Thanks in advance!

To add a bit more detail. I have another header file that contained the struct “FInventoryItem”, and this seems to compile just fine. Only “FCraftingInfo” or any struct made in the “CraftingStation.h” file gives the error.

Thanks!

I removed the include to gameplaycontroller.h from craftingstation.h, however the error remains the same.

Interactable.h
#include “GameFramework/Actor.h”
#include “Engine/DataTable.h”
#include “Interactable.generated.h”

CraftingGameMode.h
#include “GameFramework/GameModeBase.h”
#include “CraftingGameGameMode.generated.h”

CraftingGameCharacter.h
#include “GameFramework/Character.h”
#include “Engine/DataTable.h”
#include “CraftingGameCharacter.generated.h”

Haha thanks Rueben, it was going pretty well until I hit somewhere near the end where I cant get the structs to register in the GameplayController. But this probably due to me experimenting with it and adding some child objects of AInteractable that weren’t in the tutorial.

Hmm, I can’t see any other obvious cycles, and it’s actually UHT which is producing the error about what looks like a perfectly valid USTRUCT type.

One thing you might try is deleting your Intermediate folder (you’ll need to re-generate projects after doing this). This will clean out all the UHT generated files and force it to re-parse everything (just in case the cycle got its cache in a weird state).

I gave that a go, but I am still getting the same error. I will try to keep looking for a work around.

I kept at the problem and corrected it with the following steps:

  • Removed the code from the files. Saved, and recompiled without it.
  • Added code back in manually and saved.
  • After this the same code compiled fine.

Not sure if this will help anyone but that is what corrected it.