Skip to main content

Demo: Connection Control

In normal operation, the InworldController will automatically connect to the server and attempt to reconnect if the connection is lost when you start a game. This demo will show you how to have more control over the connection, such as deciding when to connect and when to disconnect, to optimize your connection time.

1. Opening the sample scene

In the Project Panel, click Assets > Inworld.AI > Scenes > SampleConnection to open the demo scene and establish a connection.


2. Connect to server

In this demo, the character will not talk to you and the connection to the server will not be established automatically. You will need to click the Play button to manually establish the connection.


If you are starting the scene for the first time, clicking the Play button will call InworldController::Init(), which will perform some additional processes such as acquiring session tokens on the first run.

If you end the session and click Play again during runtime, you will call InworldController::Reconnect(), which significantly reduces the connection time.

Please check the API Reference for InworldController.cs for more details.

public async void PlayPause()
if (m_PlayPause.isOn)
if (!m_HasInit)
await InworldController.Instance.Disconnect();

3. Disconnect

Once connected, the Play button will change to a Stop button, which you can use to manually end the communication session.Clicking this button will call InworldController::Disconnect(). Please check the API Reference for InworldController.cs for more details.


4. Connection Status

Once the client has connected to the Inworld server, the connection status will be displayed. The ping latency will be shown on the left. You can make the Ping Duration in the SessionCanvas component larger to reduce the frequency of ping calls. By default, it is set to call every 0.1 seconds.


5. Microphone and Audio

Once connected, the switch buttons for the microphone and audio will be interactive. You can click the Microphone button to turn audio capturing on or off, and click the Audio button to turn audio receiving on or off.

By clicking the Microphone button, you will change the boolean property of IsCapturing in the InworldController. By clicking the Audio button, you will change the boolean property of IsMute in the AudioInteraction of the InworldCharacter.

Please check the corresponding API Reference for more details.

public void MicrophoneControl()
InworldController.IsCapturing = !m_SwitchMic.isOn;

public void SwitchVolume()
InworldController.Instance.CurrentCharacter.Audio.IsMute = m_Mute.isOn;