How to extract input field data from one scene to the next?

Hi,

In my multiplayer game, players can login to a chat and then they can start a match. The login & chat happens in the main menu scene and it’s an asset I purchased.

Because of this I’m not sure how to store whatever players type into the Input field as their username and how to display it above the players once the game has started and a new level has been loaded.

I found a post that mentioned the following to find the text in the input field, but it requires for the canvas withholding the input field to be added to each player in the inspector, and this is not possible since the level loading means the canvas from the menu scene will always be missing: userNameInputText = canvas.transform.Find(“InputLogin/Text”).GetComponent();

Can anybody tell me how I can store and keep whatever a player types into the input field in the menu scene as a username, and how to then display that in a new canvas/text above the players?

Usually you don’t store values in input fields. You can have something like

class GameSession {
  public static readonly GameSession CurrentSession = new GameSession();

   public User CurrentUser { get; private set; }

   public void Login(string username, string password, Action<LoginResponse> callback)
  {
    // todo send request to server, wait for response and invoke callback
   }
}

This is primitive solution, but also easy to understand and implement.

1 Like

Thank you for your reply and help. I was hoping for something simple like how to: Get info from the input fields child object “Text” and show it above each corresponding player…

Well, you can get value from input field of current player, but you can’t reach input fields on other players machines. Each player needs to login to the server and send his nickname to the server and then other clients will request players list from the server in order for all players to know all other player names.
Internally the chat plugin you use must be doing exaclty this. All chats works this way. Probably, you may get info from it. But I can’t advice here since never used chat plugins. Chat is very simple thing and also there’s IRC.