How can I call a function in my gamemode from an actor (cyclic dependency)?

I am having trouble with this. I am including my CustomActor.h in my CustomGameMode class. Therefore I cannot also include my CustomGameMode.h in my CustomActor class or I’ll get a cyclic dependency error. The problem is I need to send some information to the GameMode whenever my Actor is clicked, but I can’t seem to access the GameMode from my Actor. Can anyone help?

I’ve had this problem with PlayerController and the HUD class. You solve cyclic dependency issues with forward declarations as described here in this tutorial

It didn’t work. I’m still not able to get the CustomGameMode object so I can call a function. It just says:
pointer to incomplete class type is not allowed

Its all about how you order things. You need forward declares in the .h files then in the .cpp files you include the actual header file of the class you forward declared in the header. As that tutorial says you cant access members of forward declare variables in the .h file or you will get an error. Here is an example

          // DefaultPlayerController.h header file
            #pragma once
            
            #include "DefaultPlayerController.generated.h"
            
            class AGameHUD; //forward decalre our circular dependency on AGameHUD
            
            UCLASS()
            class ADefaultPlayerController : public APlayerController
            {
              AGameHUD* GetGameHUD();
            }
            
            // DefaultPlayerController.cpp
            
            #include "GameHud.h" // we now include our forward declare class in the .cpp file so we can use it without errors
            #include "DefaultPlayerController.h"
            
            
            ADefaultPlayerController::ADefaultPlayerController(const class FPostConstructInitializeProperties& PCIP)
            : Super(PCIP)
            {
            }
        
        AGameHUD* ADefaultPlayerController::GetGameHUD()
        {
        	return Cast<AGameHUD>(this->GetHUD());
        }

Then its just the opposite in GameHud.h…forward declare class ADefaultPlayerController. Then in GameHud.cpp include DefaultPlayerController.h

Oh, I see how this works now. Thanks for the example. Much appreciated.