How do I access the live audio feed?

Sometimes, for example if you want to do lip-syncing or if you want to add an graphical equalizer representing the audio coming from ODIN, you need to get access to the AudioSource and AudioClipfrom ODIN.

This is how you can get access to those information. Somewhere in your code, you attach the ODIN playback component representing a user to the game object using the function OdinHandler.Instance.AddPlaybackComponent. This will return an instance of PlaybackComponent. Use this component to get access to the AudioClip:

Playback = gameObject.GetComponent<PlaybackComponent>();
AudioSource source = Playback.PlaybackSource;
AudioClip clip = Playback.PlaybackSource.clip;

What is UserData?

Every peer (i.e. player) connected to ODIN has it’s own user data. Within ODIN, this is just a byte array that you can use for everything. We provide a class that provides basic user data as a JSON object. CustomUserDataJsonFormat exposes that interface and provides convenience functions for serialization.

You can set the user data before joining a room or you can also update the user data afterwards:

// Generate a JSON User Data object with the players netId and name in the network
CustomUserDataJsonFormat userData = new CustomUserDataJsonFormat(name, "online");
userData.seed = netId.ToString();

// Join ODIN Room ShooterSample and send user data
OdinHandler.Instance.JoinRoom("ShooterSample", userData.ToUserData());

The method ToUserData serializes the data stored in the CustomUserDataJsonFormat instance to a JSON string and FromUserData will take the serialized JSON string and return an instance of CustomUserDataJsonFormat as shown in this code snippet:

public void OnMediaRemoved(object sender, MediaRemovedEventArgs eventArgs)
    OdinUserData userData = OdinUserData.FromUserData(eventArgs.Peer.UserData);
    PlayerScript player = GetPlayerForOdinPeer(userData);
    if (player)

Please check out our guide on user data:

Building does not work anymore after ODIN integration

Sometimes, you might see these errors after ODIN integration when building your game or app for Mac (or eventually iOS).

Building Library/Bee/artifacts/MacStandalonePlayerBuildProgram/Features/odinsdk-FeaturesChecked.txt failed with output:
Failed because this command failed to write the following output files:

UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

Sometimes, they look a bit different, but whenever you get those erros after ODIN integration the following steps might help.

ODIN needs access to your microphone. Apple will show a dialog on macOS and iOS asking users to give permission to that. In this dialog box, a text is shown provided by the app developer outlining why access to the microphone is required.

You need to set this text in the Player Settings. To do that, open the Build window with File -> Build Settings. At the bottom left corner you see a button to the Player Settings. Player Settings can also be found in the Project Settings.

In the Player Settings you’ll find these text entry fields in the Mac Configuration section as shown in this image:

Player Settings with usage descriptions

Player Settings with usage descriptions

Enter a text in Microphone Usage Description that makes sense for your users so that they understand why that should give access to their microphone.

Does 4Players ODIN support Apple Silicon?

Yes. It does. But its important that you run the Unity Editor with Apple Silicon support. At time of this writing only version 2021.2 and above are available in an Apple Silicon version. Install the Unity Hub in version 3.x to install Apple Silicon Unity editor.

Using the Unity Hub to install Apple Silicon version

Using the Unity Hub to install Apple Silicon version

Download the Unity Hub here:

Download Unity Hub

I get an UnityException when leaving PIE or loading a new scene.

UnityException: get_dataPath can only be called from the main thread.

Due to the asynchronous nature of leaving a room operation, the current recommendation is to avoid invoking this function within OnDestroy if the scene is being unloaded. Scene unloading could occur when transitioning between scenes or shutting down an application.

Instead, the best practice is to call the LeaveRoom function and subsequently wait for the OnRoomLeft event to be triggered. Once this event has been triggered, it is then safe to perform further actions, such as calling LoadScene or Application.Quit.