Unity’s popularity has been rising in the last decade thanks to its multiplatform capabilities. Lately, thanks to AR/VR/XR developments, its usage and functionality have increased further.
It’s now possible to do WebRTC streaming in Unity with Ant Media Server!
By using Unity, it is possible to develop many different types of applications, from gaming to music player. And now, you will be able to stream your application in ultra-low latency streaming by using the Unity WebRTC SDK.
Capabilities of Unity WebRTC SDK
You can achieve publishing, playing, and conferencing capabilities in various environments such as Windows, iOS , Android, and macOS.
- Could publish WebRTC stream which could be played by other Android devices, iOS devices, and browsers (mobile or desktop).
- Could play WebRTC stream which is published by other Android devices, iOS devices, and browsers (mobile or desktop).
- Could join or create conference room that is created in Ant Media Server.
- You can stream, play and join conferences in IOS, macOS, Windows, and Android.
Let’s see how to stream in a such versatile environment with ultra-low latency.
Prerequisites for Unity WebRTC SDK
Unity WebRTC SDK is free to download. You can access them through this link on antmedia.io. If you’re an enterprise user, it will be also available for you to download on your subscription page. Anyway, after you download the SDK, you can just unzip the file. You could also obtain a trial version of Ant Media Server Enterprise Edition from here.
This WebRTC Streaming In Unity guide assumes you have installed Unity.
Run the Sample Unity WebRTC SDK App
Once you downloaded the sample Unity WebRTC SDK, open unity and open the downloaded sample. After opening the sample, add the scene you want to: Sendonly, Recvonly, Multi_sendrecv.
- Sendonly is publish only.
- Recvonly is to play streams.
- Multi_sendrecv is for conferences.
After selecting the scene, set your signaling url which is your websocket url of your Ant Media Server:
After setting the signaling URL, we are ready to go. Now set the channel id which is your stream id for scenes sendonly and recvonly. But it is your room name in the conference which is multi_sendrecv scene.
Lastly, click to start streaming/playing to start ultra-low latency streaming/playing.
For the desktop environment, that is enough to start streaming/playing but for mobile platforms, iOS /Android requires a few more steps. Let’s see additional steps to enable mobile platforms to have WebRTC streaming in Unity.
Change the CPU to ARM64 in Platform settings-> Android settings in the libSoraUnitySdk.so inspector.
Set the Graphics APIs to Vulkan
Put Vulkan first in the Graphics APIs in Player Settings-> Other Settings.
Set Android 7.0’Nougat’ (API level 24) or higher in Minimum API Level
Select Android 7.0’Nougat’ (API level 24) or above in Player Settings-> Other Settings-> Minimum API Level.
Set ARM64 in Target Architectures.
Check ARM64 in Player Settings-> Other Settings-> Target Architectures.
Change the settings of iOS Plugin
libwebrtc.a’s Inspector-> Select Platform for plugin-> Uncheck Any Platform and set Include Platforms to check only iOS.
Also, do the same thing for the iOS plugin.
libSoraUnitySdk.a Inspector-> Select Platform for plugin-> Uncheck Any Platform and set Include Platforms to check only iOS.
Set Target Minimum iOS Version to 10.0 or higher
Please set 10.0 or higher in Player Settings-> Other Settings-> Target Minimum iOS Version.
If you want to use the camera, you need to set the permission
Please set a comment for using the camera in Player Settings-> Other Settings-> Camera Usage Description. (Not required for recvonly and Capture Unity Camera because these scenes or unity capture camera do not use a camera)
If you want to use a microphone, you need to set the authority.
Set a comment for using the microphone in Player Settings-> Other Settings-> Microphone Usage Description. (Not required for recvonly and Capture Unity Camera because these scenes or unity capture camera do not use a camera)
You are Set for WebRTC Streaming In Unity!
Now, you are ready to stream low latency in a versatile unity environment on various platforms including iOS and Android. WebRTC streaming in Unity has never been easier like this.
You have more options for publishing with our SDK. Please check our other guides for publishing with SDKs:
- How to Use WebRTC SDK in Native Android App?
- Easy-to-use WebRTC iOS SDK Lets You Build WebRTC iOS App with 4 Lines of Code
You may also want to check out Leap Gaming: Developer of ultra-realistic 3D games deployable on multiple platforms case study.
If you have any questions, don’t hesitate to contact us.