Menu

1 / 2

The GameIdentityRegistry Pattern — Bridging Mirror netId and Socket.IO playerId

DEV Community·Magithar Sridhar·7 months ago
#DYLDGkLh
#unity3d#gamedev#multiplayer#playerid#netid
Reading 0:00
15s threshold

When you run Mirror and Socket.IO in the same Unity project, you immediately hit a translation problem.

Mirror identifies players by netId — a uint assigned at spawn time by the Mirror host. Socket.IO identifies players by playerId — a string assigned by your Node.js backend when they connect.

These two IDs have nothing to do with each other. They're generated by different systems at different times. But when a score_update arrives from your Socket.IO backend with a playerId , you need to find the corresponding Mirror NetworkIdentity to apply the effect. And when a Mirror player spawns, you need to register which playerId they belong to so future backend events can reach them.

GameIdentityRegistry is the pattern that solves this.

The Pattern

A static lookup table. Two dictionaries.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.