npruehs/ue4-rts

Team switching with units pre-placed in world

Opened this issue · 5 comments

I have 2 player starts with team index 0 and 1. A vehicle spawns next to its headquarters when the game starts, but if the server spawns on team index 1, then the headquarters are on the wrong teams. I've set the headquarters owner->team index to the corresponding player start team index, but either the player start or the headquarters is changing its associated team. Everything works as expected when the player spawns at the Player Start with index 0, however.

Hey @DertyMunke!

Can you share a few more details about your setup?

  • Is your headquarters pre-placed in the level?
  • How do you spawn your vehicle?

Hey @DertyMunke!

Sorry, I'm afraid properly assigning pre-placed units to players isn't implemented yet - or, more specifically: Assigning fixed player starts to players isn't implemented yet. While you can specify which units should be owned by which player, there's currently no way of telling a player to always spawn at a specific player start.

We had some solution in place for A Year Of Rain, but I'm not too satisfied with the results. Things got pretty messy, trying to support three different game modes, PvP, Coop campaign and a third team-based game mode, all at the same time. Thus, that solution has never been merged back.

Hey @npruehs,

I thought setting the "Team Index" of the "Player Start" to the same number as the "Initial Owner Player Index" of the unit placed in scene would make the unit on the same team as that "Player Start." I just need the unit to be spawned on the left of one player start and to the right of the other for symmetry and fairness to the players. Do you have any suggestions on how to achieve that, or is it time for me to start diving into the code? If code, do you know off hand which class is most likely to handle this behavior or where is a good place to begin the dissection?

Team index and player index are two different things. Depending on your game, you might create a 2v2 game mode for instance, with player index [0..3] and just team index 0 and 1 available.

With being able to assign player owners to pre-placed units through setting the InitialOwnerPlayerIndex of your RTSOwnerComponents, the key is just to make sure that the player with the correct index spawns at the correct player start.

As you've already noticed, right now, player starts just feature a team index. So, to achieve what you're trying to do, you probably want to add a Player Index to the player starts, and then change ARTSGameMode::RestartPlayerAtPlayerStart to assign the player index of each player accordingly. The current implementation calls GetAvailablePlayerIndex to find any player index that's not in use, but you'll probably want to use the one matching your player start instead.