The Official Player2 AI NPC Plugin for Godot
The Player2 AI NPC Godot plugin allows developers to easily create AI NPCs in their Godot projects.
The plugin uses free AI APIs from the player2 App
Just open Player2, and the plugin connects automatically, so you can dive right into building your world instead of wrestling with keys or settings. When your game is ready, we’ll share it with our community of 40,000+ active players eager for AI-driven adventures on our discord
Most up to date download is here on github. Feel free to drag and drop only the addons folder into your project.
The plugin is also available in the godot asset library
Player2 now supports a Web API that requires NO launcher to access, but does require authentication. Thankfully the Godot plugin handles authentication for you, the only thing you need is your client_id.
A backend portal for creating a client_id is present here: https://player2.game/profile/developer
Populate your client_id under Project Settings -> Player2 -> Game Key
To jump right in with a Chat agent, open templates/chat/chat_template.tscn and get started!
To spawn in an AI NPC agent that can talk and perform actions in the world, add a Player2 AI NPC Node:
Then, open the node and modify the description of the agent
An agent chat example can be found under dev_scenes/simple_chat/simple_chat.tscn
To talk to the agent, call it's chat function. To notify the agent of stimuli from the world, call it's notify function.
For example, we have a simple interface example with a text_sent signal that is fired when the user types in a chat box and presses enter. This can get hooked into the chat function to talk to the agent.
Hearing back from the agent can be done with the agent's chat_received signal. Hook this up to a function that can read the agent's reply.
Access TTS support and the characters from the Player2 launcher using the Character Config
You can set the Voice ID to get a custom voice. View all voice IDs here
To have more control over the bot's TTS, you can manually create a Player2TTS node and assign it to the agent. However, a default TTS node is populated automatically at runtime.
By default, an agent will remember the previous chat history and greet the player at the start. This can be disabled under the Chat Config:
First, create a script that contains functions that the agent will call.
Then, add this script to an empty Node.
Then, drag the new node into the Scan Node for Functions property in the AI NPC node
You should now see a list of functions with their descriptions below:
If you wish to simply run AI/LLM chat completion without history, TTS, or agent replies, use the Player2AIChatCompletion node.
The interface is similar to the Player2AINPC node.
An example can be found under dev_scenes/simple_completion/simple_completion.tscn
Use the Player2TTS node to use Text To Speech manually.
An audio source output will be automatically created for you, but can be manually set in the node.
Use the Player2STT node to easily access Speech To Text
However, in order to do this audio must first be enabled in the godot engine.
Enable audio in godot:
Use the Player2AIImageGeneration node to generate AI images.
Use the generate_image function and the generation_succeeded signal to receive your generated image.
Use cache to avoid hitting the endpoint multiple times for the same image.
An example of image generation can be found under dev_scenes/image_gen/image_gen.tscn
Project Settings -> Audio -> Enable Input (turn it on).
If you wish to disable the error logging at the top of the screen, customize request timeouts, or customize the authentication UI for the Web API, modify the resource at addons/player2/api_config.tres
The plugin provides cloud-based user data storage for saving player progress, inventory, achievements, and other game state.
# Save player data (auto-serialized to JSON)
Player2API.Data.set_value("inventory", {"sword": 1, "shield": 2, "potions": 5}, func():
print("Inventory saved!")
)
# Load player data (auto-deserialized from JSON)
Player2API.Data.get_value("inventory", func(value):
if value:
print("Loaded inventory: ", value)
else:
print("No saved inventory found")
)
# Delete a specific key
Player2API.Data.delete("old_save", func():
print("Old save deleted!")
)
# Clear all user data (useful for "reset progress" feature)
Player2API.Data.delete_all(func():
print("All progress reset!")
)All methods accept an optional on_fail callback:
Player2API.Data.get_value("progress",
func(value):
print("Got progress: ", value),
func(error_msg, error_code):
if error_code == 404:
print("No save data yet - new player!")
else:
print("Error: ", error_msg)
)- 4 MB quota per user per game
- Data is stored as JSON strings
- Requires user authentication via Player2 app