Capture Photo from Camera
Use the device camera to capture a photo and display it in your game UI.
Actions Required
Variables Needed
cameraStatus (Enum: CameraAccessStatus)
capturedTexture (Texture2D)
errorCode (Int) (optional)
errorDescription (String) (optional)
Implementation Steps
1. State: CheckCameraPermission
Action: MediaServicesGetCameraAccessStatus
Next: Use an Enum Switch/Compare on cameraStatus:
Authorized / NotDetermined β CapturePhoto
Denied / Restricted β ShowPermissionError
2. State: CapturePhoto
Action: MediaServicesCaptureContent
Inputs:
customTitle: "Take Photo" (optional)
Events:
successEvent β ConvertToTexture
failureEvent β GetCaptureError
Note: This opens the native camera UI and waits for the callback.
3. State: ConvertToTexture
Action: MediaServicesGetContentTexture
Inputs:
contentIndex: 0 (first/only captured image)
Outputs:
texture β capturedTexture
Next: This action finishes when conversion completes. Use the stateβs FINISHED transition β DisplayPhoto.
4. State: DisplayPhoto
Assign capturedTexture to UI Image component:
5. (Optional) GetCaptureError
On failureEvent, call MediaServicesGetCaptureContentError to read errorCode + errorDescription.
Permission Denied: Guide user to Settings to enable camera access
Camera Unavailable: Check if device has a camera (some tablets don't)
Texture is Null: Ensure ConvertToTexture completes before accessing texture
Memory Issues: Large photos can use significant memory; consider resizing
iOS:
Requires "Privacy - Camera Usage Description" in Info.plist
Permission prompt shown automatically on first use
Android:
Requires CAMERA permission in AndroidManifest.xml
Permission request may show before camera opens
Texture Size: Captured photos can be large (4K+); resize if only displaying thumbnails
Memory Management: Dispose of textures when no longer needed
Preview vs Final: Consider showing preview before converting to final texture
Last updated