1
\$\begingroup\$

The player avatars in my current project are rather complex and can be configured in a variety of ways. Configurations can be saved and switched between during the game, similar to e.g. an RPG where you can design and play multiple characters.

An avatar is assembled at runtime from a configuration object (that holds only the necessary information, in the form of primitives and arrays) and several prefabs. In single player mode, configuration objects are usually serialized and saved to a file.

In multiplayer, I would like players to be able to select a handful of configurations saved earlier and transmit those across the network so that each client can assemble the other players' avatars locally. This would happen at the start of a match. Configurations do not change during a match, so synchronizing changes is not an issue.

However, I can't seem to find an elegant way to do this with Unity's new networking API. While not by much, the data's too big for a single packet. The size can also vary a bit based on user choices.

Adding transaction and chunk IDs to each packet would be doing protocol level work in the game logic and comes with a number of caveats.

Opening a separate TCP connection seems easier, but would circumvent the UNet API that handles the rest of my network code and probably require users to forward an additional port for internet games.

Splitting up the logic and letting Unity sync every detail on a GameObject/NetworkBehaviour scale (after assembling the avatar) would be incredibly wasteful.

Since configurations are user created data, Asset Bundles don't seem to be an appropriate solution either.

Is there a way to utilize existing Unity functionality to transfer this data or am I better off just rolling my own solution?

Ideally, I would like to avoid creating temporary files or opening unnecessary connections in the process.

\$\endgroup\$
  • \$\begingroup\$ You need a way to break the data into smaller pieces, fit the pieces into packets, and reconstruct it on the other end. I did this once in Minecraft before learning there was already a multipacket system available, it was a pain in the ass, and the system I was building was later deprecated with something way better. Presumably there'd be a way to do something similar in Unity, but I don't know its netcode well enough. \$\endgroup\$ – Draco18s Feb 24 '18 at 18:52
  • \$\begingroup\$ @Draco18s That's pretty much my question. I can serialize the data to a stream, add my own metadata to each chunk and piece them together on the other end, request a resend if a packet gets dropped etc. but in that case I'd be better off just using a TCP connection instead of reinventing the wheel. \$\endgroup\$ – Ruther Rendommeleigh Feb 24 '18 at 20:36
  • \$\begingroup\$ Right. I'm just not sure how to do that in Unity \$\endgroup\$ – Draco18s Feb 24 '18 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.