Maybe I'm asking dumb question, but this problems bothers me...
So I have my networked game in Unity (client), and server written in C# (without Unity). I Use ENet library for networking. Most of networked components are written by myself (lobby, components etc.).
Server doesn't know about Unity entities like players, obstacles etc. In most cases I send message ("hide object with id 4") to the server, and server pass that message to other clients where they applied message information.
What my problem is, how to assign proper IDs to networked objects, that will be the same across all players?
What I do is that:
- On all clients I get all components with specific network component (e.g. NetworkRigidbody)
- I sort all of objects using special comparer which compares based on component name with all parents appended to it
- ID is just an index in sorted array
Above algorithm works, but I have a feeling that in normal games that problem is handled in other manner.
I searched over Mirror, MLAPI and other libraries source code and I couldn't find how entity id is generated, especially when server is not Unity application.