Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spawn ids are still used in bot processes #57

Open
NicEastvillage opened this issue Nov 3, 2024 · 11 comments
Open

Spawn ids are still used in bot processes #57

NicEastvillage opened this issue Nov 3, 2024 · 11 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@NicEastvillage
Copy link
Contributor

NicEastvillage commented Nov 3, 2024

The start-up protocol was reworked in #49 and #48 to use agent_id instead of the multi-purpose spawn_id. The agent_id allows us to bind processes to bots/scripts without relying on core to start the bot/script process with a RLBOT_SPAWN_ID env var. We decided to keep spawn_id as a concept due to their usefulness internally. However, spawn_ids are still used by bot processes in the current implementation (Bots know their spawn_id since it is passed to them in the ControllableInfoTeam message). Externally spawn_ids are used for:

  • Bots find their in-game name (e.g. "Nexto (2)") by comparing their spawn id to bots in the match settings.
  • The SetLoadout message uses spawn_id.

Both of these can be replaced with better alternatives:

  • The bots are passed their in-game name in ControllableInfo instead. (🟨 TODO)
  • The SetLoadout message use game packet index instead. (✅ implemented)

With these changes, ControllableInfo do not need to include spawn_id anymore. Additionally, spawn_id also appears in the PlayerConfiguration and ScriptConfiguration, but with the above changes I don't think that is necessary anymore either. Let me know if I am wrong on that.

EDIT:

Spawn ids have one last use-case for users (from what I can tell). That is to pair PlayerInfos in the GamePacket with PlayerConfigurations in the MatchConfiguration. This is relevant because RLBot is not guaranteed to preserve the ordering. For example, human players are always pushed to the end, such that if they leave the match there won't be holes in the GamePacket players.

This is a feature we can't remove. Whether spawn ids are the best way to do it is another question. For example, the PlayerInfo could simply contain a configuration_index that is its index in the MatchConfiguration.

@NicEastvillage NicEastvillage added enhancement New feature or request question Further information is requested labels Nov 3, 2024
@VirxEC
Copy link
Collaborator

VirxEC commented Nov 4, 2024

spawn_id still has applications for bot devs, with it being a unique identifier for bots. I don't think it should be removed from GamePacket even if those other changes go through.

@NicEastvillage
Copy link
Contributor Author

In which cases are the packet index not a unique identifier?

@VirxEC
Copy link
Collaborator

VirxEC commented Nov 6, 2024

It's not unique between matches (might be helpful for custom match managers that control custom game modes) & between scripts and bots. This gave me significant headache in core when I tried to remove spawn ids completely.

@VirxEC
Copy link
Collaborator

VirxEC commented Nov 6, 2024

Sure, we can change SetLoadout to take the the index (can be converted to spawn id internally by core) and add the process's name to ControllableInfo - not sure how hard that latter one will be to implement, might be tricky or trivial I forgot when that info in congregated - but I'm against removing it from GamePacket

@NicEastvillage
Copy link
Contributor Author

NicEastvillage commented Jan 7, 2025

I think I finally found a satisfying explanation for why spawn ids are useful for users (e.g. rlgym_compat).

They can be used to pair PlayerInfos in the GamePacket with a PlayerConfiguration in the MatchConfiguration. This is relevant because RLBot is not guaranteed to preserve the ordering. For example, human players are always pushed to the end, such that if they leave the match, there won't be holes in the GamePacket players.

This is understandably a feature we can't remove. Whether spawn ids are the best way to do it is another question. For example, the PlayerInfo could simply contain a configuration_index that is its index in the MatchConfiguration.

EDIT: Added this to the issue description.

@VirxEC
Copy link
Collaborator

VirxEC commented Jan 10, 2025

One thing of note if we switch to indices - ControllableInfo currently provides a spawn id, and the process infers whether it should look for a bot or a script by what class the process inherited (e.x. Bot or Script). However, if something messes up and a bot gets passed the spawn id of a script, we know something has gone wrong because we won't be able to find the spawn id of the script in the list of bots.

However if we switch to indices, the bot will try to assume control over the wrong bot. This would then fallback on core to reject these player inputs for the wrong bot, which it will do, but the bot process itself won't have any way of knowing that something went wrong.

@NicEastvillage
Copy link
Contributor Author

If core passes a bot the wrong spawn id (or index), then it is a bug in core that needs to be fixed. Maybe it can happen if two different bots/scripts have the same agent id, but we should be able to detect that too in core and abort.

@VirxEC
Copy link
Collaborator

VirxEC commented Jan 12, 2025

perhaps that should be a new issue? we've agreed that spawn ids are staying

@NicEastvillage
Copy link
Contributor Author

I have not agreed to them staying yet. I will take a deeper look when I find time.

@VirxEC
Copy link
Collaborator

VirxEC commented Feb 18, 2025

Spawn ids are used in rlgym_compat as guaranteed unique keys for a dictionary of the cars -> https://github.com/JPK314/rlgym-compat/blob/rlgymv2-rlbot-v5/rlgym_compat/game_state.py#L120-L133

@NicEastvillage
Copy link
Contributor Author

Unless the dict keys are used somewhere else too I don't see why this could not be changed to use index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
Status: No status
Development

No branches or pull requests

2 participants