Problem with Game Instance not setting variable properly

I am currently developing a system for my game where after the number of players that will be playing has been selected in the main menu, the game goes to a widget where the players need to press enter or start to add their controller to an array of input detectors that will be used from level to level. The main menu and the regular game mode for the levels are 2 different game modes. The problem I am having is when I set the array inside the main menu game mode, I can’t seem to retrieve it in the other game mode.

Where I define and set the 2 arrays (Player Controllers and Input Detectors):

What the arrays look like in the game instance:

Where I try and retrieve the Player Controllers Input Detectors arrays:

When that last For loop executes, it prints out “None”. It does this for both arrays.
It’s worth noting that the game mode switches from the Main Menu game mode to the regular game mode between the first image and the last one. I know that passing variables actually works this way because I already set up a variable to track the number of players alive and it works just fine. The array types are for pawns (input det.) and player controllers.

I’ve been trying everything I can think of for hours on end and I feel like I’m probably just missing something obvious but I have no idea what it is. If anybody can help me, I’d very much appreciate it. Thanks for any/all help! :slight_smile:

I don’t completely understand your setup, but a few points to keep in mind:

  1. Game Mode only exists on the Server.
  2. Game Instances only exist on Clients.
  3. Player Controller exists on the Server and on the Client where this controller is used.

What I think happens is, Game Instance is unable to save all Player Controllers in itself, because most of them don’t exist there. Player Controllers are pointers → it means that any variable of a Player Controller that you have is a reference to one and the same object in memory. Game Mode, being in a server, has access to all the Player Controllers, but Game Instance does not.

Why don’t you save Player Controllers in the second Game Mode without transferring them from one to another? [Post Login] function will provide you with all the player controllers you need.


I eventually found my own solution. I was trying to have 1 controller per player per game mode. Turns out that that’s a stupid way to try and do things so I rebuilt my system so that player and pawns in the main menu get their own controller and then when the game mode goes from the menu GM to the game GM, it will spawn new pawns and controllers.
I didn’t know that controllers and player pawns are cleaned up after level swaps and game mode changes.