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 /
  • Help Room /
avatar image
3
Question by Theodus · Aug 18, 2017 at 11:06 PM · networkingmultiplayermultiplayer-networkingmultiplayer networking

UNET NetIDs for Scene Objects Mismatched Between Client and Server

While working on a multiplayer project, I've encountered a rather bizarre issue. My online scene includes a few objects with NetworkIdentities. From the documentation, it seems that NetworkIdentities in the scene at compile time will be disabled on scene load at runtime, then enabled via NetworkServer.SpawnObjects. This does occur, but for some reason, the NetworkInstanceIds of some objects become swapped with others which leads the client to think object A is object B. That is, the server assigns the NetId of 1 to object A and 2 to B, but the client sees it reversed, which puts objects in the wrong location. Weirder still, it seems to set object A's position to B's position, but keep object A's rotation, so it's not a straight transform mix-up.

I've reproduced this issue in both 5.6.2f1 and 5.6.3f1. I couldn't find anything in the docs or elsewhere online. Help would be greatly appreciated!

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
2

Answer by Malace · Aug 22, 2017 at 06:09 AM

Truth is UNET does not keep accurate track of network ID's from what I can tell. While your server player likely gets the correct A to B correlation. Your client generates different ID's for those same objects. It might likely be due to lag delay in the clients packets. Or something causing the stack trace to load object B before A. Thus assigning its first available netid to the wrong object. The same thing can happen when generating Net ID's for players. So making a distinction there can cause the same headache.

You're case may be easier to solve. in your code for your object a and b. Make a system to track each instance. Static int, or increment a item ID of your own on spawn. Make a return method for said ID. After that you can foreach the return of each object. IE:

     [command]
     void CmdMySpawnCommand()
     {
         GameObject myObjectToSpawn = (GameObject)Instantiate(myObjectToSpawnPrefab, vector3.zero, Quanternion.Identity);//<This is where the server object is made.
          
         //instantiate your objects in batch with a tag to identify them later.
         //you pretty much can only change basic component values of the object here. Set Int, float, string, ect. No object refrences, transforms/vector 3's ect.
         NetworkServer.Spawn(myObjectToSpawn);//<This is where a client creates the object.
         RpcMySpawnRPC();//call your RPC command and setup all objects regardless of server vs client. This should make any changes you need to the object.
     }
 
     [clientRPC]
     void RpcMySpawnRPC()
     {
         foreach (GameObject a in GameObject.FindObjectsWithTag("MyObjectTag"))//< you could use this to build a list of the objects or just straight to their custom script components
        {
             if (a.GetComponent<MyObjectScript>().ReturnMYObjectIDMETHOD() == 0)
             {
                 ///this is object A set its location. To iterate through all of these quickly you will need to store the inteded x, y, and z of the object. as well as its rotation vector x, y ,z. internally if you want to set it prior to this point via double foreach loop.
 
             }
 
         }
     }




Without code that its my best guess as I ran into something similar with players. NetworkIdentity as I said doesn't seem to sync correctly. Just got past this myself so if you need more info just ask.

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

170 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 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

How to find local player gameobject? c# 3 Answers

How to decide an asynchronous multiplayer solution for a turn based mobile chess game? 0 Answers

How to smoothly interpolate game object positions in a network game? 0 Answers

How configure a dedicated server about Unet 0 Answers

Assign Network Manager an Online Scene with Script 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