by Pivec Labs
TutorialCharacter + Broadcast Screen

Character + Broadcast Screen

⏱ 10–15 min Uses the shipped CharacterBroadcastDemo scene

Prerequisites: NetCrafter Relay 2.0 with com.unity.webrtc 3.0.0+ installed; a server running the 2.0 rendezvous service; Unity's free Starter Assets: First Person Third Person Character Controllers imported (as for the Character tutorial); two machines, builds or Editor instances. A webcam on the host is optional.

What you'll see: The Character demo with an 8 m screen in front of the spawn point. The host broadcasts to every player: a pre-recorded clip, their live camera, or nothing — switching live, without anyone reconnecting. Players walk around and watch together; the host's microphone plays from the screen.

01

Open the demo scene#

text
Assets/PivecLabs/Examples/LiveDemos/CharacterBroadcast/CharacterBroadcastDemo.unity

Or click Open Character + Broadcast Screen in Settings → Live (Voice & Video). It's a copy of the Character demo plus:

  • BroadcastScreen — the screen (frame, posts, title) with two DemoWorldSpaceVideoDisplay components: the host sees its own feed, viewers see the received one. Its AudioSource is 3D, so the host's voice comes from the screen, at full volume within 15 m (the whole play area) and fading out by 80 m.
  • LiveBroadcast — NetCrafterLiveBroadcast + NetCrafterLiveRelayLink + BroadcastScreenSource.
  • BroadcastHostCanvas — a small panel, shown only to the host: current source, viewer count, and the keys.
02

Server and settings#

Both demos need the 2.0 rendezvous service on your server — it's what lets the call or broadcast reuse the game's join code. New server: run the Server Setup Wizard (Tools → Pivec Labs → NetCrafter Relay → Settings). Server set up with 1.x: run the wizard against it once and choose Update / redeploy (same port, credentials and data).

The broadcast uses the CharacterDemo Definition's Relay Settings, the same as the game.

03

Play it#

  1. Host: enter a name, click Host, then continue into the game. The screen plays the first video from StreamingAssets/BroadcastVideos (see step 04 — until you add one it shows “No videos”; press 2 for the live camera instead) and the host panel shows Broadcasting: Pre-recorded video.
  2. Players: join with the host's game code. A moment later they see the same picture on the screen — no second code.
  3. Host keys (the mouse is locked during gameplay, so these are keyboard shortcuts):
text
1   play video
3   next video
2   live camera (first webcam found)
0   off air

Switching is instant for everyone: the broadcast always sends one texture, and BroadcastScreenSource only changes what is drawn into it, so viewers never reconnect.

04

Use your own video#

The package contains no video — the Asset Store does not allow video files in packages — so add one before testing the video mode (any short .mp4 or .webm). To show videos without rebuilding the game, put them in the BroadcastVideos folder inside StreamingAssets:

text
Editor:  Assets/StreamingAssets/BroadcastVideos/
Build:   <YourGame>_Data/StreamingAssets/BroadcastVideos/
  • Video files (.mp4, .webm, .mov, .m4v): just drop them in.
  • Web links: one direct link to a video file per line in urls.txt in that folder (a link to the file itself, not a YouTube page).

As host, press 3 to step through the list and 1 to play. The folder is re-read every time you press a key, so you can add videos while the game is running. You can also set a built-in Video Clip or a Video URL on BroadcastScreenSource. Folder scanning works on Windows, macOS and Linux.

Sound: while a video plays, viewers hear the video's soundtrack (and so does the host). With the live camera or off air they hear the host's microphone. Keep captureAudio on for the broadcast to carry sound at all.

05

Add a screen to your own game#

  1. Add a GameObject with NetCrafterLiveBroadcast; assign your game's Definition (Use Definition + Assign Relay Settings); set videoSource to RenderTexture.
  2. Add NetCrafterLiveRelayLink and drag the broadcast into its broadcast field.
  3. Add BroadcastScreenSource (it creates the RenderTexture and assigns it to the broadcast) or fill customRenderTexture yourself from any camera or video.
  4. For the screen, any renderer works: put DemoWorldSpaceVideoDisplay on it twice (showLocal on and off) with the broadcast assigned.

No game code changes — the link starts the broadcast when the game is hosted and joins it when players join.

06

Troubleshooting#

  • The host's character stutters for viewers while broadcasting: the host's upload carries the video to every viewer plus its own game updates. Lower maxVideoBitrateKbps on NetCrafterLiveBroadcast (the demo uses 1000 kbps per viewer; total upload is roughly that × the number of viewers).
  • Screen stays dark for viewers: the server is still on the 1.x rendezvous service (re-run the wizard with Update / redeploy), or viewers use a different Definition's Relay Settings.
  • Key 2 does nothing: no webcam found — the host panel stays on Off air and the Console says so.
  • Video upside-down or mirrored on the screen: any video with text in it makes this obvious. The flip is set in code: in DemoWorldSpaceVideoDisplay.Awake, change the sign of mainTextureScale x (mirror) or y (upside-down) and adjust mainTextureOffset to match.
  • Player character missing: Starter Assets isn't imported — see the Character tutorial.