# Nakama Groups Sample Project

**URL:** https://heroiclabs.com/docs/sample-projects/unity/nakama-groups/
**Summary:** Groups discovery and management sample project for Unity games
**Keywords:** nakama groups, unity sdk, list groups async, list user groups async, create group async, group discovery, group management, nakama groups controller, authentication, sample project
**Categories:** unity, sample-projects, nakama-groups

---


## Code overview

#### Main controller (`NakamaGroupsController.cs`)

Coordinates all interactions with the Nakama Groups API.

**Authentication**

```csharp
// Connect to Nakama server and authenticate with device ID
await AuthenticateWithDevice();
```

**Group discovery**

```csharp
// List public groups with optional name filtering
var groupsResult = await Client.ListGroupsAsync(session, name: null, limit: 100);

// List groups the current user belongs to
var userGroupsResult = await Client.ListUserGroupsAsync(session, userId: null, limit: 100, cursor: string.Empty);
```

**Group lifecycle**

```csharp
// Create a group with custom avatar and settings
await Client.CreateGroupAsync(session, "My Guild", "A competitive PvP guild",
    avatarJson, langTag: null, open: true, maxCount: 50);

// Manage group membership
await Client.DeleteGroupAsync(session, groupId);
await Client.JoinGroupAsync(session, groupId);
await Client.LeaveGroupAsync(session, groupId);
```

**Membership moderation**

```csharp
// Manage join requests and member privileges
await Client.AddGroupUsersAsync(session, groupId, userIds: new[] { userId });      // Accept join request
await Client.PromoteGroupUsersAsync(session, groupId, userIds: new[] { userId });  // Promote to admin
await Client.DemoteGroupUsersAsync(session, groupId, userIds: new[] { userId });   // Demote to member
await Client.KickGroupUsersAsync(session, groupId, userIds: new[] { userId });     // Remove or decline request
await Client.BanGroupUsersAsync(session, groupId, userIds: new[] { userId });      // Ban permanently
```

#### Group listing (`GroupView.cs`)

Renders individual group entries with custom avatars, names, and member counts.

#### Member management (`GroupUserView.cs`)

Displays group members and join requests with role-based action buttons that adapt to the user's permissions.
