Skip to content

Async Style RPCs #3588

@harayuu9

Description

@harayuu9

Is your feature request related to a problem? Please describe.
This was originally discussed in Issue #2664, but the thread was mistakenly closed due to an unrelated PR. Historically, Unity has not been friendly to Task-based async programming, leading many developers to rely on third-party libraries like UniTask for async-style RPCs. As a result, Unity projects often diverged from idiomatic modern C# patterns.


Describe the solution you'd like
With Unity 6000, AwaitableCompletionSource and related awaitable APIs have been officially introduced, making it possible to write async/await-style code natively in Unity. I believe this is a good time to revisit and formally consider adding support for awaitable RPCs within the Netcode library.


Describe alternatives you've considered

  • Custom implementations using AwaitableCompletionSource
    While technically possible, implementing async-style RPCs using AwaitableCompletionSource comes with significant complexity and maintainability challenges:

    • Each RPC function requires manually setting up an AwaitableCompletionSource, assigning unique IDs, managing mappings, handling timeouts, and propagating exceptions.
    • A naive implementation risks calling SetResult() on the wrong completion source due to out-of-order network execution. This makes ID management a necessity, even for simple use cases.
    • Repeating this setup for every RPC function that returns a result leads to boilerplate-heavy and fragile code.
    • Furthermore, because RPCs must be declared inside NetworkBehaviour, generalizing or abstracting common logic becomes difficult, making reuse and maintainability even harder.

Given these obstacles, providing first-class support for async/await RPCs in the Netcode library would offer significant ergonomic and architectural benefits.


Additional context
Now that awaitable primitives are officially supported in Unity, the ecosystem is in a much better position to embrace modern asynchronous patterns. Adding native support for async-style RPCs would modernize the developer experience, reduce boilerplate, and align Unity Netcode with the direction of contemporary C# development.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stat:awaiting-triageStatus - Awaiting triage from the Netcode team.stat:reply-neededAwaiting reply from Unity accounttype:featureNew feature, request or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions