I want to use the GameModeClass function in another class

While viewing this article, you are practicing a simple UI window popup when the player enters the overlap volume actor using UMG.

In the above document, I thought that I had to declare a function that launches a widget in the game mode class, and call the ChangeWidgetClass function in game mode in the AOverlap::OverlapBegins function of the overlap volume actor class. So I created a game mode class instance in the overlap volume actor class and the engine was shut down as soon as
the player’s phone hit the overlap volume.

Can not I create a game mode class instance within another class?

  • Recommended if you have a better example that pops up the UI when overlap

I assume you want to call function in game mode? There should be only one AGameMode and by spawning AGameMode somewhere you creating 2nd one and engine don’t expect two to exist in same time, thats why it may crash. Keep in mind that there class insistence already created by the engine and you can get them using already existing functions like:




You should not create incenses of major game defining classes like AGameMode, APlayerController etc. and practically any other class based of AInfo, this is handled by the engine it self and those classes. By doing that you might only duplicating them and create dead objects which can mess up the engine work routine as it does not expect more manually created objects of those classes to exist.

Also keep in mind in multiplayer that AGameMode, APlayerController objects exists only on server side for security reasons (so user can’t modify them with memory modifiers). Anything they do in the server will be naturally applied to clients via actors they interact with.

thank you. I solved the problem thanks to this. XD