Getting Started

This documentation explains the steps to create a room system for a multiplayer game with Reflective. The process explained here is a simplified, understandable version of the actual process in a real game. It doesn't work this way for every project or design, but it provides a basic recipe and mindset for the process.

Network Manager Setup

  • Add a new game object to the Scene and rename it “NetworkManager”.

  • Add the ReflectiveNetworkManager component or your class derived from the ReflectiveRoomManager class to the newly created game object

  • Add the NetworkManagerHUD component to the game object. This provides the default UI for managing the network game state.

Room Manager Setup

  • Add a new game object to the Scene and rename it “RoomManager”.

  • Add the RoomManager component or a component derived from RoomManagerBase to the newly created object

Player Prefab Setup

  • Find the Prefab for the player game object in the game, or create a Prefab from the player game object

  • Add the NetworkIdentity component to the player Prefab

  • Set the Player Prefab in the NetworkManager’s Spawn Info section to the player Prefab

    • Or if you are going to use a special player creation system for the room, simply add it to the SpawnablePrefabs section. Then you can create wherever you want.

  • Remove the player game object instance from the Scene if it exists in the Scene

Player Prefab Configuration

  • Uncheck the Auto Create Player checkbox via NetworkManager. In this way, we can write a synchronous system for the formation of the player when the room is created in accordance with the room system.

  • If you have a player object in the lobby, such as a lobby player, you can tick the Auto Create Player tick. The room system will replace the lobby player with the game object required for the game when the room is created.

An example for a synchronous system to occur when the room is created;

public class RoomPlayerSpawn : NetworkBehaviour
    {
        [SerializeField] private GameObject _gamePlayerPrefab;
        [SerializeField] private GameObject _lobbyPlayerPrefab;
        
        private int _playerCount;

        //If true, it creates a player object for your player in the lobby when you leave the room.
        //If your project has such a design, mark it.
        [SerializeField] private bool _useLobby;
        
        // Necessary event assignments are being made
        [ServerCallback]
        private void Start()
        {
            RoomManagerBase.Instance.Events.OnServerJoinedRoom += CreateGamePlayer;

            //If the lobby option is used, create a player for the lobby when leaving the room,
            //otherwise it will only delete the player.
            if (_useLobby)
                RoomManagerBase.Instance.Events.OnServerExitedRoom += CreateLobbyPlayer;
            else
                RoomManagerBase.Instance.Events.OnServerExitedRoom += PlayerCreatorUtilities.RemovePlayer;
        }
        
        [ServerCallback]
        private void CreateGamePlayer(NetworkConnection conn, uint roomID)
        {
            PlayerCreatorUtilities.TryCreatePlayerOrReplace(conn, _gamePlayerPrefab);
        }
        
        [ServerCallback]
        private void CreateLobbyPlayer(NetworkConnection conn)
        {
            PlayerCreatorUtilities.TryCreatePlayerOrReplace(conn, _lobbyPlayerPrefab);
        }
    }

Interest management Setup

  • If your project will use the room system to create more than one room and use it in a design with a scene for each room, you need to add a SceneInterestManagement to the object where the RoomManager is located.

  • If you are using SceneInterestManagement or a script derived from it, you will need PhysicSimulator to validate physical interactions.

  • There will be a PhysicSimulator inside the asset. This PhysicsSimulator is a basic and useful Simulator, so it allows you to use it in many of your projects without making any changes.

Remote Actions

  • Events are available for all transactions such as room formation and participation. In this way, you can make designs suitable for your project in a modular way.

Spawn object for room scene

  • To create objects in the game in your project, you must specify the scene during creation in multi-room systems.

  • There is a utility class in the asset for this operation. With this class, you can create objects both on the server and on the stage.

Last updated