block-quote On this pagechevron-down
Features chevron-right π Web Viewchevron-right PlayMaker chevron-right Use Cases Custom URL Schemes Register custom URL schemes for WebView-to-Unity communication (OAuth callbacks, deep linking, custom protocols).
Actions Required
Variables Needed
webViewInstance (Object): Stores the WebView instance
customScheme (String): Custom scheme (e.g., "myapp", "unity", "oauth")
targetURL (String): URL to load
matchedURLScheme (String): The full URL that matched the scheme
Implementation Steps
1. State: CreateWebView
Action: WebViewCreateInstance
Outputs:
webViewInstance β Store in FsmObject variable
2. State: RegisterScheme
Action: WebViewAddURLScheme
Inputs:
webViewInstance β From variable
urlScheme β customScheme variable (e.g., "myapp")
Events:
successEvent β LoadContent
failureEvent β ShowError
Note: Register schemes BEFORE loading content that might trigger them.
3. State: LoadContent
Action: WebViewLoadURL
Inputs:
webViewInstance β From variable
url β targetURL variable
4. State: ShowWebView
Action: WebViewShow
Inputs:
webViewInstance β From variable
Events:
failureEvent β ShowError
5. State: ListenForScheme (Parallel FSM recommended)
Action: WebViewOnURLSchemeMatchFound
Inputs:
webViewInstance β From variable (optional filter)
Outputs:
matchedURLScheme β Store in an FsmString variable
Events:
onMatchEvent β ProcessCallback
Pattern: This listener stays active until a matching URL is clicked.
6. State: ProcessCallback
Parse matchedURLScheme for parameters
Handle OAuth tokens, deep link data, etc.
Scheme not recognized : Ensure scheme is registered BEFORE loading URL
Wrong URL format : Schemes must be lowercase, format: scheme://path?params
Multiple WebViews : Use instance filter on WebViewOnURLSchemeMatchFound
Parameters not parsing : URL decode parameters before using
Use lowercase scheme names (e.g., "myapp", not "MyApp")
Register all schemes before loading content
URL encode parameters in web links
URL decode parameters when processing in Unity
Use descriptive paths: myapp://login/success vs myapp://callback
Handle errors gracefully (invalid tokens, missing parameters)
Example Configurations
Payment Confirmation
Multi-Action Callbacks
URL Parameter Parsing
Example JavaScript for website to construct callback URLs:
Example Unity processing (in ProcessCallback state):
Security Considerations
Validate all parameters from callback URLs (don't trust client data)
Use HTTPS for OAuth flows (protect tokens in transit)
Implement CSRF protection for sensitive actions
Verify OAuth state parameters to prevent replay attacks
Never include secrets in callback URLs (use server-side validation)
Advanced: Multiple Schemes
Register multiple schemes for different purposes:
Last updated 3 months ago