Up to date
This page is up to date for Godot 4.3
.
If you still find outdated information, please open an issue.
YoutubePlayablesClientΒΆ
Inherits: ThirdPartyClient < Node < Object
Node for using the Youtube Playables SDK.
DescriptionΒΆ
Node for using the Youtube Playables SDK.
Implementation based on the official Youtube Playables SDK. Official documentation for this service on developers.google.com/youtube/gaming/playables/reference/sdk.
You can test your game on developers.google.com/youtube/gaming/playables/test_suite.
MethodsΒΆ
void |
|
void |
|
open_yt_content(video_id: String) |
|
send_score(value: int) |
SignalsΒΆ
audio_enabled_change(enabled: bool) π
Emitted when the audio settings change event is fired from YouTube.
pause() π
Emitted when a pause game event is fired from YouTube.
When a pause game event is fired from YouTube, audio_enabled_change is emitted.
Note: You have a short window to save any state before your game gets evicted.
Pause and resume requirements.
resume() π
Emitted when a resume game event is fired from YouTube.
When a resume game event is fired from YouTube, audio_enabled_change is emitted.
Method DescriptionsΒΆ
YoutubePlayablesResponse get_language() π
Returns the BCP-47 language tag for the user's language set in YouTube.
Note: this may be different than the system or browser language settings but should always match the language used in YouTube.
Returns an empty String if called outside the Youtube Playables environment.
The YouTube Playables SDK version.
Returns an empty String if called outside the Youtube Playables environment.
Returns whether the game audio is enabled in the YouTube settings.
Returns true
if called outside the Youtube Playables environment.
bool is_youtube_environment() π
Whether or not the game is running as a playable.
if is_youtube_environment():
print("Youtube Playables SDK version is " + get_sdk_version())
YoutubePlayablesResponse load_data() π
Loads game data from the YouTube cloud in the form of a serialized string. This API is usually called before the game loads to resume the game state.
var result: YoutubePlayablesResponse = await load_data().finished
if result.has_error():
push_error(result.error)
log_error()
else:
var data: Dictionary = JSON.parse_string(result.data)
print("Player is at level %d." % data["player_level"])
Note: Signed-out players are not supported. The YoutubePlayablesResult.data will be empty.
void log_error() π
Logs an error to YouTube.
Note: This API is best-effort and rate-limited which can result in data loss.
void log_warning() π
Logs a warning to YouTube.
Note: This API is best-effort and rate-limited which can result in data loss.
YoutubePlayablesResponse open_yt_content(video_id: String) π
Open a YouTube video given a valid video_id
.
This will open the video in a new tab on web and in the miniplayer on mobile.
YoutubePlayablesResponse save_data(data: String) π
Saves game data to the YouTube cloud in the form of a serialized string.
It is recommended to save your data immediately after important milestones.
var data: Dictionary = {"player_level": 42}
var result: YoutubePlayablesResult = await save_data(JSON.stringify(data)).finished
if result.has_error():
push_error(result.error)
log_error()
Note: Signed-out players are not supported. YoutubePlayablesResponse.finished returns without errors but the data is not be saved.
YoutubePlayablesResponse send_score(value: int) π
Sends the user's best score to YouTube.
The score should represent one dimension of progress within the game. If there are multiple dimensions, the developer must choose one dimension to be consistent. Scores will be sorted and the highest score will be displayed in YouTube UI so any in-game high score UI should align with what is being sent through this API.