Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: Not Selected
more ▼

asked Jun 29 '14 at 12:56 PM in C++ Programming

avatar image

563 59 164 125

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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


more ▼

answered Jun 29 '14 at 02:53 PM

avatar image

123 3 7 13

avatar image Kochab Jun 29 '14 at 03:18 PM

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

avatar image jaran Jun 29 '14 at 04:57 PM

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
             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

avatar image Kochab Jun 29 '14 at 10:54 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question