• 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 03gramat · May 17, 2014 at 10:44 AM · networkrpcnetworkviewnetworkviewid

AllocateViewID over RPC but the NetworkView doesn't exist

Hello!

TL;DR: I set a NetworkViewID from server and tell all clients to create an object and set it's NetworkViewID to that, but t$$anonymous$$s error occurs when a 2nd client joins (3 players). (Go and look at the picture and script below you lazy person)

I have been stuck on t$$anonymous$$s error for a good few days now. I have a scene setup where I am running an authoritative server. When a client joins the servers game it requests a player to be made and in-turn, the server creates a NetworkViewID for it, and sends an unbuffered RPC to all clients (custom buffer when a new client joins to reduce overall buffer).

All clients then create a copy of the new client gameobject and set their networkview to the one created by the server (and passed through). T$$anonymous$$s then allows all clients to have a copy of the server-set networview player gameobject w$$anonymous$$lst allowing the specific new client to adjust variables in their own copy (including the camera attached w$$anonymous$$ch is the reason it is set up t$$anonymous$$s way).

The error occurs when the 2nd client (3rd player) joins the game (and onwards) and has the error for the NetworkVIewID that is allocated to the FIRST client to join the game (ID: 2).

My only thought is that the split second between the clients creating the new object and setting it's networkview, the game stores SOME data and feels it should be sending that to new clients.


 @RPC // Called by the new client ONLY to RPCMode.Server
 function spawnClientRequest(info : NetworkMessageInfo){ // recieves networkplayer from info.sender
     
     var viewID : NetworkViewID = Network.AllocateViewID(); // create new id for new client
     
     for(var clients in GetComponent(playersInGame).players.Keys){ // for all clients already made
         
         networkView.RPC("spawnOldClients", info.sender, GetComponent(playersInGame).players[clients]);//make copies on new client
     }
     
     networkView.RPC("spawnClient", RPCMode.All, viewID, info.sender); // don't buffer, that way we reduce errors and lag from stored rpc's
 }
 
 @RPC
 function spawnClient(viewID : NetworkViewID, asker : NetworkPlayer){ // Spawns client as requested
     
     var made = Instantiate(playerPrefab, transform.position, transform.rotation); // Create the client's object on all
     
     yield WaitForSeconds(1); // give it some time
     
     if(made.GetComponent(NetworkView).networkView.viewID != viewID){ // set created object networkID to server-set one (giving server control)
     
         made.GetComponent(NetworkView).networkView.viewID = viewID;
     }
     
     if(Network.isServer){ // Take control and store it's object and networkID in a dictionary
     
         made.GetComponent(movement).enabled = true;
         
         GetComponent(playersInGame).players[made] = viewID; 
     }
     
     if(asker == Network.player){ // if t$$anonymous$$s is the object WE asked for... allow me to watch the camera over shoulder
     
         made.transform.Find("Camera").GetComponent(Camera).enabled = true;
         made.transform.Find("Camera").GetComponent(AudioListener).enabled = true;
         sceneCam.enabled = false;
     }
 }
 
 @RPC
 function spawnOldClients(viewID : NetworkViewID){
 
     var made = Instantiate(playerPrefab, transform.position, transform.rotation);
     
     yield WaitForSeconds(1);
     
     if(made.GetComponent(NetworkView).networkView.viewID != viewID){
     
         made.GetComponent(NetworkView).networkView.viewID = viewID;
     }
 }

Image available here: http://imgur.com/zH0aTUJ

One of the most tedious parts of t$$anonymous$$s error is that it works fine with the first client, bun bot the second one.

Any help would be greatly appreciated, any other questions you have, feel free to ask!

Cheers,

Matt

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

2 Replies

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

Answer by 03gramat · Jan 15, 2015 at 02:20 PM

I actually managed to work out an authoritative server method and have created a tutorial on it:

https://www.youtube.com/watch?v=QfzrpxO89tU

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
avatar image
0

Answer by Bunny83 · Jun 06, 2014 at 11:13 AM

Well, why do you yield for a second? You have to instantiate the object and assign the viewID ASAP or the next network update will cause errors.

Comment
Add comment · Show 1 · 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
avatar image 03gramat · Jun 14, 2014 at 07:52 PM 0
Share

I tried out removing the yield, I remember I tried it to fix a previous bug that is now irrelevant, however, removing the yield didn't change the result.

Thanks for the response though!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

View ID AllocatedID: # not found during lookup. Strange behaviour may occur 1 Answer

How do you remove RPC's from the RPC buffer that where created on behalf of a player that is now disconnected with an authoritative server? 1 Answer

single call to RPC or Local function? 2 Answers

Sending info to/from different networkViews 1 Answer

Inaccurate network position 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