Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by makransov100 · Jun 07, 2018 at 05:49 AM · networkingpositiontransport

UNET Transport Level API Efficient Message Handling and Types?

Along with a friend of mine, we have started development of a multiplayer game utilizing the Transport Level API (UNET LLAPI?) available with the Unity Game Engine. Because of the need to have up to a hundred concurrent users in the view range of other players I was wondering what is the most efficient way to send messages about the player position, rotation, etc.

So far, adapting from the tutorial (1) on Youtube we were able to set up a system where only the positions of the different moving players are updated. However even with only 5 players moving at the same time the position updates get super delayed on the different clients.

I believe this is due to the string variable type that is used for the messages of the different data. Therefore my main question would be how do I utilize Unity's Transport Level API Data Events at maximum efficiency per message (in this case lets just say for position updates where movement is possible in any direction of the 3d space (x,y,z))

Here is the code that we have for the server script... Just like in the tutorial before calling the correct function every message string is split with appropriate delimiters separating the arguments that are received from the client. The client has a similar message receiving system with a different set of functions. The code below code is of course in Update function of the Server script.

 NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
     switch (recData)
     {
         case NetworkEventType.Nothing:
             break;
         case NetworkEventType.ConnectEvent:
             Debug.Log("Player " + connectionId + " has connected");
             OnConnection(connectionId);
             break;
         case NetworkEventType.DataEvent:
             string msg = Encoding.Unicode.GetString(recBuffer, 0, dataSize);
             Debug.Log("Receving from " + connectionId + " : " + msg);
             string[] splitData = msg.Split('|');
 
             switch (splitData[0])
             {
                 case "NAMEIS":
                     OnNameIs(connectionId, splitData[1]);
                     break;
 
                 case "MYPOSITION":
                     OnMyPosition(connectionId, 
                                               float.Parse(splitData[1]),
                                               float.Parse(splitData[2]), 
                                               float.Parse(splitData[3]));
                     break;
 
                 case "MOVESELECT":
                     OnMoveSelect(connectionId, 
                                                 bool.Parse(splitData[1]), 
                                                 new Vector3(float.Parse(splitData[2]),
                                                                        float.Parse(splitData[3]), 
                                                                        float.Parse(splitData[4])));
                     break;
                 case "NEWPLAYERSTARTED":
                     OnNewPlayerStarted(connectionId);
                     break;
                 case "POSITIONTOANOTHER":
                     OnPositionToAnother(connectionId, 
                                                             float.Parse(splitData[1]), 
                                                             float.Parse(splitData[2]), 
                                                             float.Parse(splitData[3]), 
                                                             int.Parse(splitData[4]));
                     break;
                 default:
                     Debug.Log("invalid Message : " + msg);
                     break;
             }
             break;
         case NetworkEventType.DisconnectEvent:
             Debug.Log("Player " + connectionId + " has disconnected");
             OnDisconnection(connectionId);
             break;
         case NetworkEventType.BroadcastEvent:
             break;
     }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by makransov100 · Jun 08, 2018 at 06:34 AM

The lagging problem was fixed by utilizing a while loop to receive all of the queued up messages with NetworkTransport.Recieve.

Answered here: https://stackoverflow.com/questions/50733564/unet-transport-level-api-efficient-message-handling-and-types

Answer Source: https://forum.unity.com/threads/low-level-api-networktransport-receive-fabulously-slow-is-this-by-design.413725/

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

138 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unet Transport Layer problem 0 Answers

Update position via state syncronization results in weird movement. 0 Answers

Network Interpolated Transform resets position? 1 Answer

Best Unet. 0 Answers

How do I smoothly sync players position over the network in Unity3D(UNet) without bugs? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges