Loading...
Connecting Players via Steam
Project Type Personal project
Software Used Unreal Engine 4
Languages Used C++, Blueprints
Primary Role(s) Multiplayer programming

I learned a lot in this project actually, I learned about ue4 multiplayer system(replication),
Online Steam subsystem, Advanced UI, Some C++ optimization, Server client Model... etc.




    • Stage One:
      • Connecting Players via local network in ue4 through Hamachi(VPN).
      • Client and server approach and why it is better than peer to peer approach.
      • Replications and Server Authority (Server always right and has the authority to replicate other actors).
      • Hosting Server with server Travel that makes the players travel from (Lobby to Game Map).
      • All of that with Using Ue4 Command line in next stage i improved that.
    • Stage Two:
      • Creating Advanced UI Menu so players can connect without the use of command line.
      • Creating Menu Elements using C++.
      • After this stage we start enabling the steam subsystem.
    • Stage Three:
      • Using Steam SDK and UE4 Online Subsystem to make multiplayer functionality.
      • Creating and joining Sessions.
      • enabling GameMode for lobby so that we can start a game when the number of joined players reached a decided number by us
      • seamless travel and non seamless travel


  Creating Game Session
Here I created the game session:




Code Snippit:
UCLASS()
class PUZZLEPLATFORMS_API UPuzzlePlatformsGameInstance : public UGameInstance, public IMenuInterface
{
	GENERATED_BODY()
	
public:


	UPuzzlePlatformsGameInstance(const FObjectInitializer & ObjectInitializer);
	void Init();

	UFUNCTION(BlueprintCallable, Category = "Menu")
	void LoadMenuWidget();

	UFUNCTION(BlueprintCallable, Category = "Menu")
	void LoadPauseMenu();

	UFUNCTION(Exec)
	void Host(FString ServerName) override;
	
	UFUNCTION(Exec)
	void Join(uint32 Index) override;

	void StartSession();

	virtual void LoadMainMenu() override;

	virtual void ExitGame() override;

	virtual void RefreshingServerList() override;

private:
	TSubclassOf MenuClass;
	TSubclassOf InGameMenuClass;
	TSharedPtr SessionSearch;
	IOnlineSessionPtr SessionInterface; // we can't forward declear this bvecause it will need a pointer and it is interface.
	class UMainMenu* Menu;



	FString DesiredServerName;

	void OnCreateSessionComplete(FName SessionName, bool Success);
	void OnDestroySessionComplete(FName SessionName, bool Success);
	void OnFindSessionsComplete(bool Success);
	void OnJoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type Results);
	void CreateSession();
};
		

  Creating MainMenu UI Entirly in C++
Created Responsive U.I Functionality All in C++


MainMenu

InGameMenu

ServerRow


UCLASS()
class PUZZLEPLATFORMS_API UMainMenu : public UMenuWidget
{
	GENERATED_BODY()
public:

	UMainMenu(const FObjectInitializer & ObjectInitializer);

	void SetServerList(TArray ServerNames);
	void SelectIndex(uint32 Index);


protected:
	virtual bool Initialize() override;

private:
	UPROPERTY(meta = (BindWidget))
	class UButton* HostButton;

	UPROPERTY(meta = (BindWidget))
	class UButton* JoinButton;

	UPROPERTY(meta = (BindWidget))
	class UButton* CancelButton;

	UPROPERTY(meta = (BindWidget))
	class UButton* ConfirmJoinServerButton;

	UPROPERTY(meta = (BindWidget))
	class UButton* RefreshServerListButton;

	UPROPERTY(meta = (BindWidget))
	class UButton* QuitButton;

	UPROPERTY(meta = (BindWidget))
	class UButton* ConfirmHostAServerButton;

	UPROPERTY(meta = (BindWidget))
	class UButton* HostServerCancelButton;

	UPROPERTY(meta = (BindWidget))
	class UEditableTextBox* ServerNameTextBox;


	UPROPERTY(meta = (BindWidget))
	class UPanelWidget* ServerList;

	UPROPERTY(meta = (BindWidget))
	class UWidgetSwitcher* MenuSwitcher;

	UPROPERTY(meta = (BindWidget))
	class UWidget* JoinMenu;

	UPROPERTY(meta = (BindWidget))
	class UWidget* HostAServerMenu;

	UPROPERTY(meta = (BindWidget))
	class UWidget* MainMenu;

	TSubclassOf ServerRowClass;


	UFUNCTION()
	void HostServer();

	UFUNCTION()
	void OpenJoinMenu();

	UFUNCTION()
	void RefreshServerList();

	UFUNCTION()
	void OpenHostAServerMenu();

	UFUNCTION()
	void ReturnToMainMenu();
	
	UFUNCTION()
	void JoinServer();

	UFUNCTION()
	void QuitClicked();

	void UpdateChildren();

	TOptional SelectedIndex;


		


Click Here To Go To The Project On Github






Copyright © 2018 by Mazen Morgan and David Wagih