MirrorNetworking / MirrorNetworking/Mirror

Async spawning to better support Addressables

Open
#2,061 7 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C#
Stars
6.3k
Forks
870
PR merge metrics
No merged PRs in 30d

Description

Please explain the suggested feature in detail.

Addressables allows prefabs to be loaded from asset bundles at runtime. Prefabs are normally spawned via

Addressables.InstantiateAsync("AssetAddress");

or

Addressables.LoadAssetAsync<GameObject>("AssetAddress");

Both of these methods are asynchronous and have a completed event when they are finished.

How exactly does this keep you from releasing your game right now?

With the current spawn handlers within mirror it is not possible to call these methods as the handlers return a result right away.

The alternative is to list the prefab early to make sure they exist by the time mirror wants to spawn them, this reducing some of the benefits of being able to load and unload assets when they are needed.

Can you suggest a possible solution?

Add another version of the spawnHandlers that does not return the game object right away, but instead passes a callback into the handler. That callback would then be called by the user's handler after InstantiateAsync has finished. The callback would then apply the spawn message.

One possible problem with this may be future messages being received on the client before they have finished loading the prefab. We may need to add a way to queue up messages for a netId and apply them after the callback is called.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing Mirror's current spawn handlers and the Unity Addressables InstantiateAsync and LoadAssetAsync flows. Define the callback lifecycle and how messages for a netId are handled while loading; done means Addressables-prefab spawning works asynchronously without losing subsequent client messages.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, unity
Domain
game-dev, networking
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.