My agent is written in Python and works with a Uni...
# ask-ai
b
My agent is written in Python and works with a Unity application. When I run the following code I get the exception "Application error in method handler." What could cause this?await ctx.room.local_participant.perform_rpc( destination_identity=target.identity, method=unity_method_name, payload=payload_json, response_timeout=8, )
✅ 1
t
Thanks for reaching out, Mat. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're seeing an "Application error in method handler" when calling
perform_rpc
from your Python agent to Unity. I can help troubleshoot; a few likely causes and quick checks first: • The Unity participant has not registered an RPC handler for the method name in
unity_method_name
. Confirm Unity calls
room.registerRpcMethod(<that name>, handler)
. • The Unity handler throws an exception or returns an invalid response. Check Unity logs for exceptions inside the handler and ensure it returns a proper RPC response or
RpcError
. • Payload shape or types don't match what Unity expects (JSON structure, missing fields, or types). Verify
payload_json
matches the handler's expected schema. • The handler takes longer than the
response_timeout
(8s) and times out, which can surface as an application error. Try increasing
response_timeout
to test. • Identity mismatch: confirm
target.identity
is the Unity participant's current identity and that the participant is connected and reachable. Please tell me: 1. Do you see any error or stack trace in the Unity logs when the RPC is invoked? If so, paste it. 2. How is the Unity handler registered (method name) and what does it expect as the payload? A short snippet helps. 3. Does the RPC ever succeed with a simpler payload or a no-op handler on Unity? With those details I can suggest targeted fixes or specific code checks. Sources: client-sdk-js | livekit/livekit_composite | DeepWiki | Build a healthcare intake assistant with an Anam avatar | LiveKit, with interactive elements
b
On the Unity side, what RPC responses are considered "proper"?
t
Good question — I'll explain what a "proper" RPC response from the Unity side looks like and what to return so the Python
perform_rpc
call succeeds. • Success response: return a serializable value (JSON string is recommended). The value should contain the result data your caller expects and be returned before the caller's
response_timeout
elapses. • Error response: throw an
RpcError
(or the Unity SDK equivalent) with an integer error code and a descriptive message (optionally details). This sends structured error info back to the caller instead of a generic failure. • Other requirements: ◦ Ensure the RPC method is registered with the exact method name used by the caller (
room.RegisterRpcMethod(methodName, handler)
). ◦ Catch internal exceptions in your handler and convert them to
RpcError
rather than letting unhandled exceptions propagate. ◦ Keep payload parsing/validation robust: validate the incoming JSON and return a clear
RpcError
for bad input. If you’d like, paste your Unity handler code (or the method name and expected payload) and I’ll point out exactly what to change. Sources: Forwarding to the frontend | LiveKit Documentation | Build a healthcare intake assistant with an Anam avatar | LiveKit | client-sdk-unity | livekit/livekit_composite | DeepWiki, with interactive elements