Organizing Teams


I have a multiplayer game with several teams and I’m wondering where to store team information. I was thinking the best place would be the GameState so it’s replicated and accessible anywhere. But in my components I need to know if a target pawn is in an enemy team. I could iterate over each team array to first find my own pawn and then to check if the target pawn is in another team, to make sure I can attack. But iterating every time I want to cast a spell sounds like it could become a performance problem. Are there other recommended ways to check if pawn A is in the same or another team than pawn B? Should I use tags instead of arrays?

I was thinking to create a TeamComponent that I attach to each pawn, which would store which team a pawn is in, so I could quickly access the information without iterating over the whole team arrays, but that probably comes with its own share of overhead. Any recommendations?

Thanks in advance

GameState is the correct place. Iteracting over an array is not as hard as you think. Such algorithms like checking if an reference is in an array happen thousand times per second in a game engine.

Thanks, then I will go with that approach.