I'm making a multiplayer game with Unreal Engine, and I need to run some blueprint code on the client after they have connected to the server. This includes creating the HUD widget, uploading the player's loadout, etc. Where should I put this code so that it runs only on the client after connecting to a server?

  • \$\begingroup\$ You could use a boolean value that gets changed whenever the connection is made. Now, what exactly you have in mind? Why you want this code to run only after a connection is made? This looks like an XY problem. Tell us what you intend to do, probably the solution you are suggesting here is not the best one for what you really want. \$\endgroup\$ – rlam12 Jun 12 '16 at 2:32
  • \$\begingroup\$ @rlam12 Players can have different loadouts, which are stored on their computer. After they log in to the server, the client needs to tell the server which loadout they have equipped (the server will verify that it is valid). \$\endgroup\$ – FlyingPiMonster Jun 12 '16 at 13:03

In the sense the game framework is built upon, you define the HUDClass in the GameMode Class. The HUD code only runs on the client.

If you want to do something at the beginning, right after spawning and possessing the Pawn, I suggest you override BeginPlayingState inside the PlayerController and start from there (you can call GetHUD and start asking the hud to do whatever you want to show to the player).

In general, actions from the player should be done through the PlayerController, so if you want to show something on the HUD based on a player action you could use the PlayerController for that and then the PlayerController "delegates" the "business logic" of actually displaying the thing to the HUD class itself.

If you want to know more about the Gameplay Framework, consider reading this: https://docs.unrealengine.com/en-US/Gameplay/Framework/index.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.