What Problem Does This Solve?
Mobile users hold their devices in portrait (vertical) or landscape (horizontal) orientation. Social media platforms like Instagram Stories, TikTok, and YouTube Shorts expect vertical video (9:16), while traditional YouTube prefers horizontal (16:9).
LckCameraOrientation lets you set the output orientation to match how users hold their device or the platform they’re targeting.
When to Use This
Use LckCameraOrientation when:
- Building a mobile app with recording/streaming
- Supporting social media uploads (TikTok, Instagram, Snapchat)
- Users can rotate their device during gameplay
- Creating platform-specific content (vertical for Stories, horizontal for YouTube)
Skip this if you’re desktop-only or always output the same orientation.
Quick Example
// Switch to portrait for TikTok/Instagram Stories
var result = lckService.SetCameraOrientation(LckCameraOrientation.Portrait);
if (!result.IsOk)
{
Debug.LogError($"Failed to set orientation: {result.Message}");
}
// Switch to landscape for YouTube
lckService.SetCameraOrientation(LckCameraOrientation.Landscape);
How It Works
Camera orientation determines the aspect ratio of the output video:
Portrait (Vertical)
- Aspect ratio: 9:16 (e.g., 1080×1920)
- Matches vertical phone orientation
- Best for: TikTok, Instagram Stories, Snapchat, Reels
Landscape (Horizontal)
- Aspect ratio: 16:9 (e.g., 1920×1080)
- Matches horizontal phone orientation
- Best for: YouTube, traditional video platforms
The orientation affects how the resolution is interpreted. A CameraResolutionDescriptor(1080, 1920) in portrait mode outputs vertical video, while landscape swaps it to 1920×1080.
Common Patterns
Auto-detect device orientation
void Update()
{
var currentOrientation = Input.deviceOrientation;
if (currentOrientation == DeviceOrientation.Portrait ||
currentOrientation == DeviceOrientation.PortraitUpsideDown)
{
lckService.SetCameraOrientation(LckCameraOrientation.Portrait);
}
else if (currentOrientation == DeviceOrientation.LandscapeLeft ||
currentOrientation == DeviceOrientation.LandscapeRight)
{
lckService.SetCameraOrientation(LckCameraOrientation.Landscape);
}
}
public enum SharePlatform
{
TikTok,
Instagram,
YouTube,
Twitter
}
void SetOrientationForPlatform(SharePlatform platform)
{
var orientation = platform switch
{
SharePlatform.TikTok => LckCameraOrientation.Portrait,
SharePlatform.Instagram => LckCameraOrientation.Portrait,
SharePlatform.YouTube => LckCameraOrientation.Landscape,
SharePlatform.Twitter => LckCameraOrientation.Landscape,
_ => LckCameraOrientation.Landscape
};
lckService.SetCameraOrientation(orientation);
Debug.Log($"Set {orientation} orientation for {platform}");
}
UI toggle
public class OrientationToggle : MonoBehaviour
{
public Toggle portraitToggle;
void Start()
{
portraitToggle.onValueChanged.AddListener(OnOrientationChanged);
}
void OnOrientationChanged(bool isPortrait)
{
var orientation = isPortrait
? LckCameraOrientation.Portrait
: LckCameraOrientation.Landscape;
var result = lckService.SetCameraOrientation(orientation);
if (!result.IsOk)
{
Debug.LogError($"Failed to change orientation: {result.Message}");
portraitToggle.isOn = !isPortrait; // Revert toggle
}
}
}
Resolution by Orientation
Portrait (9:16)
// Common portrait resolutions
new CameraResolutionDescriptor(720, 1280) // HD vertical
new CameraResolutionDescriptor(1080, 1920) // Full HD vertical
Landscape (16:9)
// Common landscape resolutions
new CameraResolutionDescriptor(1280, 720) // HD horizontal
new CameraResolutionDescriptor(1920, 1080) // Full HD horizontal
Make sure your resolution descriptor matches your intended orientation. A 1920×1080 resolution in portrait mode will output vertical video at 1080×1920.
| Platform | Preferred Orientation | Aspect Ratio | Resolution |
|---|
| TikTok | Portrait | 9:16 | 1080×1920 |
| Instagram Stories | Portrait | 9:16 | 1080×1920 |
| Instagram Reels | Portrait | 9:16 | 1080×1920 |
| YouTube Shorts | Portrait | 9:16 | 1080×1920 |
| Snapchat | Portrait | 9:16 | 1080×1920 |
| YouTube | Landscape | 16:9 | 1920×1080 |
| Twitter/X | Landscape | 16:9 | 1280×720 |
| Twitch | Landscape | 16:9 | 1920×1080 |
Enum Values
| Value | Description | Aspect Ratio | Use Case |
|---|
Portrait | Vertical orientation (tall) | 9:16 | Mobile-first, social media stories |
Landscape | Horizontal orientation (wide) | 16:9 | Traditional video, YouTube, desktop |
API Reference
Set Orientation
LckResult SetCameraOrientation(LckCameraOrientation orientation)
Parameters:
orientation — Portrait or Landscape
Returns: LckResult indicating success/failure
Best Practices
Match target platform — Use portrait for TikTok, landscape for YouTube
Set before recording — Orientation should be configured before starting capture
Test both modes — Ensure your UI works in both orientations
Don’t change during recording — Stop recording before switching orientation
Good Pattern
// Check if recording before changing
bool isRecording = lckService.IsRecording();
if (isRecording)
{
Debug.LogWarning("Cannot change orientation during recording");
return;
}
var result = lckService.SetCameraOrientation(newOrientation);
if (result.IsOk)
{
Debug.Log($"Orientation set to {newOrientation}");
}
Mobile Development Tips
Lock orientation in Unity
// Lock to portrait
Screen.orientation = ScreenOrientation.Portrait;
Screen.autorotateToPortrait = true;
Screen.autorotateToPortraitUpsideDown = false;
Screen.autorotateToLandscapeLeft = false;
Screen.autorotateToLandscapeRight = false;
// Lock to landscape
Screen.orientation = ScreenOrientation.LandscapeLeft;
Screen.autorotateToLandscapeLeft = true;
Screen.autorotateToLandscapeRight = true;
Screen.autorotateToPortrait = false;
Screen.autorotateToPortraitUpsideDown = false;
Handle safe areas
// Adjust UI for notches and rounded corners
var safeArea = Screen.safeArea;
rectTransform.anchoredPosition = new Vector2(
safeArea.x,
safeArea.y
);