Manually setting Team ID in Lyra..?

hey everyone. I have searched high and low for this on the web…
in Lyra … Can I set TEAM ID somehow? I get randomly assigned to be red or blue…
But if I always want to spawn as blue…?

I can’t find WHEN I’m getting assigned a team… Anyone knows?
here is a Lyra Team Creation Component but can’t set anything.
T

1 Like

You are assigned a team via this C++ function of the ULyraTeamCreationComponent:

void ULyraTeamCreationComponent::ServerChooseTeamForPlayer(ALyraPlayerState* PS)
{
	if (PS->IsOnlyASpectator())
	{
		PS->SetGenericTeamId(FGenericTeamId::NoTeam);
	}
	else
	{
		const FGenericTeamId TeamID = IntegerToGenericTeamId(GetLeastPopulatedTeamID());
		PS->SetGenericTeamId(TeamID);
	}
}

Your team is automatically assigned based on which team has the lowest population.

You can of course change that however you want, but it’s a C++ change, not a Blueprint one.

5 Likes

thank u very much for the reply! <3

I was looking for a BP solution, but as you say, there isn’t any.
I ended up using my own teams system with gameplay tags instead :slight_smile:

I also got this from the man himself Michael Noland (programmer for the Lyra project):

The teams are determined by the ULyraTeamCreationComponent subclass used in your experience, specifically the ServerChooseTeamForPlayer implementation.

By default this picks the team with the fewest players (via GetLeastPopulatedTeamID), but you can create a subclass to do whatever you want, e.g., map all humans to team 1 and all AI to team 2, or read some state from the player state indicating what team the player wants.

You’d have to make that subclass of the team creation component in C++ but you could expose functions to let you control how it works from BP in there.

ShooterGame’s experience is currently using B_TeamSetup_TwoTeams derived from LyraTeamCreationComponent.

I’m setting this as resolved.
But for all that read this and perhaps was searching for a BP solution:
There isn’t any.

5 Likes

Any example code in C++ on how to map all humans to team 1 and all AI to team 2 ?

1 Like

I made the easy way by testing directly into the C++ file \Source\LyraGame\Teams\LyraTeamCreationComponent.cpp
and it works (1 human versus 3 bots)

void ULyraTeamCreationComponent::ServerChooseTeamForPlayer(ALyraPlayerState* PS)
{
	if (PS->IsOnlyASpectator())
	{
		PS->SetGenericTeamId(FGenericTeamId::NoTeam);
	}
	else
	{
		int32 SelectedTeamID;
		if (PS->IsABot()) { // If player is a bot then team red
			SelectedTeamID= 1;
		}
		else { // If player is a human then team blue
			SelectedTeamID= 0;
		}
		// const FGenericTeamId TeamID = IntegerToGenericTeamId(GetLeastPopulatedTeamID());
        const FGenericTeamId TeamID = IntegerToGenericTeamId(SelectedTeamID);
		PS->SetGenericTeamId(TeamID);
	}
}

But anyone know a better example and can describe the good practice for a new instance class based on lyra plugins ?

9 Likes

Under LyraTeamSystem.h there is a public method not exposed to Blueprint

// Changes the team associated with this actor if possible
// Note: This function can only be called on the authority
bool ChangeTeamForActor(AActor* ActorToChange, int32 NewTeamId);

I’m checking to see what happens if I update to this:

// Changes the team associated with this actor if possible
// Note: This function can only be called on the authority
UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = Teams, meta = (Keywords = "Set"))
bool ChangeTeamForActor(AActor* ActorToChange, int32 NewTeamId);`

Edit: This works! I was able to add a new blueprint that lets me change teams.

(Now we have to figure out how to instant-kill the player)

11 Likes

Hi,
this may be caused by an update, but Team One (Red) is no longer GenericTeamID “0” but “1” and Team Two (Blue) is “2” . If you set it to zero, it messes up the team creation.

1 Like

You may want to try to use the nodes: Get Game Mode + Restart player.

1 Like

With UE5.1, is now in LyraTeamSubSystem.h.

Many thanks for this code solution.
I’ve plugged these nodes after event possessed, and there was no need to restart players:

3 Likes

Hi . Im currently wanting to do this with a non C++ solution.
As was wondering If anyone knew which BP the teams are actually being set by the lyra subsystem. So I could just disconnected that part and Come up with my own team selection code?.
Also TBH Im confused as to why this option is not even exposed to begin with as its such an important option for anyone wanting to build a multiplayer game on lyra.

It isn’t done in BPs. Changing much for the Lyra team system requires (a little bit of) C++ as of 5.2.

1 Like

Thanks. I resorted to c++ methods. Took me a while to get it right but With advice :wink: I managed to GET VS up and running. Now I just want to find a way to set team the from the UMG, team selection and Also traditional MP character class . I already got those menus ready But its a bit sketchy on which BP the UMG cast to to set them in.

Hey guys, I tried this using Unreal 5.1 and 5.3 - I exposed the Function as explained in LyraTeamSubsystem.h by changing it in a Text Editor:

// Changes the team associated with this actor if possible
// Note: This function can only be called on the authority
UFUNCTION(BlueprintCallable, BlueprintPure=false, Category=Teams, meta=(Keywords="Set"))
bool ChangeTeamForActor(AActor* ActorToChange, int32 NewTeamId);

Anyways I can not get it in the Blueprint - what part am I missing here? I would like to recreate the above shown, but in my B_Hero_ShooterMannequin Blueprint I can not create the "Change Team for Actor " function even so I changed that tiny bit of code in the .h file?

1 Like

I just rebuild LyraTeamSubSystem.h from Visual Studio and now the function ChangeTeamForActor is available in BluePrint in Unreal 5.3

3 Likes

Excuse my noob question. How do you rebuild just one file ? do you know good place to learn that ? (only found tutorial to rebuild the whole project)

I guess the user meant edited one file and hit “build” to build the entire project.

1 Like

thanks you for clarification