Download

Problem with includes

Hello. I am having some troubles trying to make my classes communicate between them and using both the same 2 enums.

Below is my code and errors:

GameplayManager.h:



...
#include "EGameStateEnum.h"
#include "MusicalBlock.h"
...
UCLASS()
class MYPROJECT4_API AGameplayManager : public AActor
{
...
private:
    EGameStateEnum GameState;
    TArray<EBlockEnum> SoundsSequence;
    TArray<TWeakObjectPtr<AMusicalBlock>> BlocksArray;

    void FindBlocks();
    void PlayBlocks();
    EGameStateEnum GetGameState();
    void CheckPlayedBlock();
...
};


MusicalBlock.h:



...
#include "EBlockEnum.h"
...
UCLASS()
class MYPROJECT4_API AMusicalBlock : public AActor
{
....
private:
    UFUNCTION()
        void OnClick(UPrimitiveComponent* TouchedComponent, FKey ButtonPressed);
    void PlaySound();
    void NotifyManager();
...
};


And the flow I want is the following:

  • The Manager finds the Blocks in the scene using FindBlocks()
  • Then, it plays the Blocks using PlayBlocks();
  • Then, the blocks play using their PlaySound() method;
  • Then, when one block is clicked, I need it to notify the manager that it’s been clicked using NotifyManager();
  • Then, the manager will use his CheckPlayedBlock() to check that the clicked block is the correct one.

The problem now is that I need a reference from the manager to all blocks (everything correct until here), but I also need a reference from the Blocks to the Manager to notify him a block has been clicked. This seems to be troublesome because of bidirection communication. And I also need them both to use the following enums:



#include "Engine/UserDefinedEnum.h"

UENUM()
enum class EBlockEnum : uint8
{
      BE_Down UMETA(DisplayName = "DOWN"),
     BE_Up UMETA(DisplayName = "UP"),
     BE_Right UMETA(DisplayName = "RIGHT"),
     BE_Left UMETA(DisplayName = "LEFT")
};




#include "Engine/UserDefinedEnum.h"

UENUM()
enum class EGameStateEnum : uint8
{
    GE_NotStarted    UMETA(DisplayName = "NOT STARTED"),
    GE_Started        UMETA(DisplayName = "STARTED"),
    GE_Ended        UMETA(DisplayName = "ENDED"),
    GE_Unblocked    UMETA(DisplayName = "UNBLOCKED"),
    GE_Blocked        UMETA(DisplayName = "BLOCKED")
};


The problem comes trying to get a reference to the GameplayManager in the MusicalBlock because of the includes I assume, if I try to put #include “GameplayManager.h” in MusicalBlock.h it gives me the following errors of undeclared variables in GameplayManager.h, which I didn’t have before:



2>c:\users...GameplayManager.h(30):: error C2065: 'AMusicalBlock': undeclared identifier
2>c:\users...GameplayManager.h(30):: error C2923: 'TWeakObjectPtr': 'AMusicalBlock' is not a valid template type argument for parameter 'T'
2>c:\users...GameplayManager.h(30):: error C3203: 'TWeakObjectPtr': unspecialized class template can't be used as a template argument for template parameter 'InElementType', expected a real type
2>c:\users..GameplayManager.h(30):.: error C2065: 'AMusicalBlock': undeclared identifier
2>c:\users...GameplayManager.h(30):: error C2923: 'TWeakObjectPtr': 'AMusicalBlock' is not a valid template type argument for parameter 'T'
2>c:\users...GameplayManager.h(30):: error C3203: 'TWeakObjectPtr': unspecialized class template can't be used as a template argument for template parameter 'InElementType', expected a real type
2>C:\Users\...\Desktop\simonultimo\...\Source\MyProject4\MusicalBlock.cpp(16): warning C4996: 'USceneComponent::AttachTo': This function is deprecated, please use AttachToComponent instead. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile.
2>C:\Program Files\Epic Games\UE_4.18\Engine\Source\Runtime\Engine\Classes\Components/SceneComponent.h(641): note: see declaration of 'USceneComponent::AttachTo'
2>ERROR : UBT error : Failed to produce item: C:\Users\...\Desktop\simonultimo\...\Binaries\Win64\UE4Editor-MyProject4-4514.dll


Hope you can help me there

The 1st post duplicated, trying to delete this one

Solved this, I had to use #include just for the enums, then reference the classes using direct forwarding and finally I was missing the #pragma once in the enum files