Social Hooks
Social Hooks are a number of functions and events that can be used to tie social engagement to Udon in your worlds.
Privacy
Every friend Social Hook can be disabled by the user by turning off Allow Worlds To Count Friends In Instance in privacy settings. A world cannot tell the difference between players who are not friends and players who are friends but have disabled the feature.
As a further privacy measure, friend counts are not directly exposed. Instead worlds are told about friends counts as a bucket.
Friends
GetLocalPlayerFriendBucket
Returns how many of the local player's friends are in the instance with them,
FriendBucket bucket = SocialHooks.GetLocalPlayerFriendBucket();
if (bucket == FriendBucket.None)
{
// No or very few friends are present.
}
else if (bucket == FriendBucket.Few)
{
// A few friends are present.
}
else if (bucket == FriendBucket.Some)
{
// Some friends are present.
}
else if (bucket == FriendBucket.Many)
{
// Many friends are present.
}
| Bucket | Friends in the instance |
|---|---|
None | 0 - 1 |
Few | 2 - 4 |
Some | 5 - 9 |
Many | 10 or more |
OnLocalPlayerFriendBucketChanged
Fires when the local player's bucket changes during a session, with the previously reported bucket and the new bucket. Friend buckets are delayed and coalesced, so they cannot be matched to one player arriving.
public override void OnLocalPlayerFriendBucketChanged(FriendBucket previous, FriendBucket current)
{
// Update the world's UI or behavior based on the new friend bucket.
}
OnLocalPlayerFriendRequestSent
Fires when the local player sends a friend request. It does not identify the other player.
public override void OnLocalPlayerFriendRequestSent()
{
// The local player has sent a friend request to someone
}
OnLocalPlayerFriendRequestAccepted
Fires when the local player accepts a friend request. It does not identify the other player.
public override void OnLocalPlayerFriendRequestAccepted()
{
// The local player has accepted a friend request
}
Groups
Social hooks provides methods for querying information about group instances.
GetInstanceGroupId
Returns the current instance’s owning group ID for Group, Group+, and Group Public instances, or an empty string elsewhere.
IsLocalPlayerInInstanceGroup
Returns whether the local player belongs to that instance’s group. Returns false outside group instances.
GetInstanceGroupInfo
Returns the current instance group’s SocialHooks.GroupInfo for Group, Group+, and Group Public instances. It includes Name, MemberCount, BannerTexture, ShortCode, Description ("About This Group"), and Rules.
The method returns GroupInfo.Empty outside a group instance or while group metadata is loading.
Favorites
HasLocalPlayerFavoritedWorld
Whether the local player has your world in any of their world favorite lists.
if (SocialHooks.HasLocalPlayerFavoritedWorld())
{
// Show a thanks message
}
OnLocalPlayerFavoritedWorld
Fires once per session, when the local player favorites the world they are currently in.
public override void OnLocalPlayerFavoritedWorld()
{
// Show a thanks message
}