Create a new level, name as MainMenu
and a new widget, called MainMenu Widget
Create a Game Instance BP, called RTS_Game Instance
Go to project setting and change the game instance
Open the BP, add new custom event:
(capital letter on ?Listen)
Go to MainMenu Widget, graph, add on clicked event on both buttons:
Check world settings if it’s as below (esp for Gamemode overide):
Open MainMenu level→ Open Level BP, set the graph:
Change the number of players to 2
Go to RTS PlayerController,
Event begin play node modify:
Make a provision for the 2nd to 4th player to spawn
Go back to TopDown map level
Make a BP actor, called PlayerStartCamp
Add following box collisions and position them as below:
Drag the BP actor in 3 corners in the scene map
Create a Gamemode based BP, name as RTS GameModeBase
Go to project setting,
change the default gamemode to RTS game mode based,
and HUD, player controller:
In both MainMenu and TopDownMap levels, world settings, set gamemode overide to none:
Open RTS Game Mode Base, construction script:
promote variable, rename as PlayerStartCamps
To event graph (setup possessing camera when event starts)
To remove selected player when game starts:
To spawn Starting Building and Units made in previous tutorials before:
Add function in RTS interface:
Go to GameMode Base graph, add below nodes (to send player start camp to player controller):
Go to Player Controller graph, add “Event setup Player Start” node by different sequence, with “spawn actor from class” nodes for each unit class:
Collapse the highlighted nodes to marcos, name as Spawn Player Starting Loadout
Open the marco and plug all the “self” in inputs node from 4 to 1:
Delete self 2 to 4, rename 1st one as PlayerStartCamp
Back to event graph, R click on the spawn node and refresh node
To authorize only host but not clients player controllers to set spawning:
Go to Parent Unit Class, Details, Pawn
Change Auto Possess AI from Place in World to Place in World or Spawned
Choose Parent unit class self, check if tick Replicates
Go to Parent Building Class, check the same thing:
Now both units and building are spawn, but cannot move the unit. To solve this:
Go back to Player Controller BP:
Ending on Right mouse button event, revise below by creating a custom event to facility multiplayer setup:
Add custom event with 2 inputs, and change replicates to run on server