Interest Management via Sync Groups
Summary
Use sync groups to partition a scene into groups which can be used to control what entities are synced to a player. Sync Groups are collections of entities that are synced to clients. The tutorial will partition a scene into regions which will be assigned to different sync groups. Players will be added to and removed from sync groups letting them only see entities in the regions near to them. This tutorial uses Tutorial 2 or 3 as a base.
Sync groups can be used for more than just spatial grid partitioning. In a city or village scene, the interior of each building could be its own sync group, and players would be added to a building's sync group when they enter the building. You could also put entities into a sync group that no players are ever added to to prevent those entities from syncing to anyone.
Requirements
Setup
Make the Platform Larger and Tilted
Select the 'Platform'.
Set the transform scale to (50, 1, 50).
Set the transform rotation to (-5, 0, 0).
Create a Sphere Entity Prefab
Create a sphere.
Add a ksEntityComponent.
Add a Rigidbody component.
Make the sphere a prefab in the 'Resources' folder.
Delete the sphere from the hierarchy.
Scripting
Create a Server Spawner Room Script to Spawn Spheres
The server spawner room script spawns spheres continuously on the high end of the tilted platform which roll down it.
Select the 'Room' object.
In the 'Add Component' menu, select 'Reactor->New Server Room Script'.
Name the script 'ServerSpawnerRoom'.
ServerSpawnerRoom.cs
Create a Server Sync Group Room Script to Partition the World into Sync Groups
The server sync group room script divides the world into cells along the XZ plane. Each cell corresponds to a sync group.
Sync groups are used to control which entities are synced to which players. All entities belong to exactly one sync group, and a player can belong to any number of sync groups and will receive all entities in those sync groups. Zero is a special sync group; entities in group zero will always sync to all players. All entities are in sync group zero by default. Sync group ids are 32-bit uints, however the highest 2 bits are reserved, so the highest possible sync group id is 2^30 - 1. The script assigns entities to sync groups based on which cell they are in. It assigns players to sync groups for cells near the player's avatar.
Select the 'Room' object.
In the 'Add Component' menu, select 'Reactor->New Server Room Script'.
Name the script 'ServerSyncGroupRoom'.
ServerSyncGroupRoom.cs
Testing
Build your scene config (CTRL + F2).
Start a local server.
Enter play mode.
Select the 'Main Camera' object.
Change the 'FollowCamera' distance to 30 to see spheres appear and disappear as they move into or out of sync group cells near the player.
Change the 'FollowCamera' distance to 10 and you should not see spheres appearing and disappearing.
Spheres will spawn on the high end of the platform and roll all the way down. If you set the 'FollowCamera' distance to 30, you can see the spheres popping into and out of existance as they move into and out of sync group cells near your avatar. As you move around, the sync groups cells you are receiving should change so you only receive nearby cells.
Last updated

