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"

Set GameMode in Plugin C++

Hey there,

I am currently developing an unreal plugin, which also contains a gamemode / playercontroller class. So I got this button in the editor working which sets up my scene for the plugin to work, the only thing that is missing is the custom gamemode, which then has to be set in the world settings manually.

I just wanted to ask if there is a possibility to set the current level gamemode in the plugins c++ code? As I said, the gamemode comes packed in the plugins content folder, it just has to be assigned...

Thanks in advance!


Product Version: UE 4.15
more ▼

asked Mar 21 '17 at 12:08 AM in C++ Programming

avatar image

18 1 2 4

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

1 answer: sort voted first

Hey Dominik,

I don't know if you still need an answer but I think I have one for you because I needed the same thing and I just found out how it works.

My setup is just like yours that I also have a custom button in the editor and as soon as I press it I do the following in the clicked method:

 UWorld* const World = GEditor->GetEditorWorldContext().World(); // Get a world reference
 AWorldSettings* worldSettings = World->GetWorldSettings();   // Get the world's settings
 worldSettings->DefaultGameMode = PluginManager::getInstance()->getGameModeClass(); 

The PluginManager here is a Singleton class that stores all the important information about my plugin that I need all the time - e.g. my gamemodeclass...

The getInstance() looks like this:

 static PluginManager* getInstance()
     return (!instance) ? instance = new PluginManager() : instance;

The getGameModeClass() looks like this:

 TSubclassOf<class AMyGameMode> getGameModeClass() const
     return this->gameModeClass;

The setter looks like this:

 void setGameModeClass(TSubclassOf<AMyGameMode> gameModeClass)
     this->gameModeClass = gameModeClass;

The member itself looks like this:

 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) TSubclassOf<class AMyGameMode> gameModeClass = nullptr;

I did the assignment inside the constructor of my gamemode, because it is executed when starting the editor and I then already have a reference to the class without having to find it with the ClassFinder: PluginManager::getInstance()->setGameModeClass(this->StaticClass());

This works if your GameMode is a C++ class. I guess if your GameMode is a BluePrint, you would have to get the Class like this:

 static ConstructorHelpers::FClassFinder<AGameMode> GameModeBPClassFinder(TEXT("/Plugin/GameModeBP"));
 if (GameModeBPClassFinder.Class != nullptr)

If you still have questions feel free to ask.


more ▼

answered May 27 '17 at 08:53 AM

avatar image

61 7 12 13

(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