Open GameMode base BP:
Add variables:
In team color Details, add 4 team colors:
Add 2 new inputs in SetupPlayerStart functions in RTS Interface:
Single linear color here, not array
Back to Game mode base graph, revise setup player start node as below
(GET node typed Get a Copy, not Get a Ref)
Continue to elaborate:
Go to PlayerController BP
promote variables for number and color in Event Setup player start node:
Set Team number variable in detail, replication as Replicated:
Go to Parent Unit Class,
add variables for color and number
For both variables in details, tick instance editable, expose on spawn, and turn replication to Replciated:
Go to Parent Building Class
Repeat the same as parent unit class
Go to player controller, Spawn players starting loadout marcos,
Refresh all spawn actor first building nodes, plug in team numbers and color variable nodes:
Go to Unit style 1, open its mesh’s material graph, R click and convert the color node as parameter,
rename it as TeamColor (for BP use):
Back to Parent Unit class, setup team color graph in event begin play node:
Repeat the same on building → Open First Building viewport, open its material:
In Parent Building Class:
Make team numbers (for selection of units from the other team):
Add 2 new functions in Interface:
Go to Parent unit class, open Get Team function node in Interface and make the graph:
Repeat the same on Parent Building Class BP
Go to Player Controller, open Is on my Team? function in interface:
Go to Marquee HUD BP, add nodes to identify team after for each loop, and before select units under rectangle graph:
(The branch true refers to only select the units, if it’s on my team)
To do the same on selecting building, go to RTS player controller, open Handle Building Click marco in left mouse button node graph:
Now the player can only select his own units and buildings