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

**URL:** <https://forums.unrealengine.com/t/how-can-i-call-a-function-in-my-gamemode-from-an-actor-cyclic-dependency/287020>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [June 29, 2014, 12:56pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-function-in-my-gamemode-from-an-actor-cyclic-dependency/287020 "2014-06-29T12:56:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kochab](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kochab](https://forums.unrealengine.com/u/Kochab)\
**Post date:** [June 29, 2014, 12:56pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-function-in-my-gamemode-from-an-actor-cyclic-dependency/287020/1 "2014-06-29T12:56:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![hard\_code](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@hard\_code](https://forums.unrealengine.com/u/hard_code)\
**Post date:** [June 29, 2014, 2:53pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-function-in-my-gamemode-from-an-actor-cyclic-dependency/287020/2 "2014-06-29T14:53:17Z")

</div>

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

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

---

<div class="post-metadata">

**Author:** ![Kochab](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kochab](https://forums.unrealengine.com/u/Kochab)\
**Post date:** [June 29, 2014, 3:18pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-function-in-my-gamemode-from-an-actor-cyclic-dependency/287020/3 "2014-06-29T15:18:35Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![hard\_code](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@hard\_code](https://forums.unrealengine.com/u/hard_code)\
**Post date:** [June 29, 2014, 4:57pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-function-in-my-gamemode-from-an-actor-cyclic-dependency/287020/4 "2014-06-29T16:57:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kochab](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kochab](https://forums.unrealengine.com/u/Kochab)\
**Post date:** [June 29, 2014, 10:54pm UTC](https://forums.unrealengine.com/t/how-can-i-call-a-function-in-my-gamemode-from-an-actor-cyclic-dependency/287020/5 "2014-06-29T22:54:09Z")

</div>

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