Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 SirMacJefferson · Jun 01, 2012 at 08:32 AM · networkingnetworkviewinstantiationviewid

Looking for some help on manually allocating NetworkViewIDs

Hey,

I've been trying to make an FPS lately. I made a server project and a client project, got a database working for storing account info, and got a simple (albeit buggy) room creation/joining system up.

I use RPCs to locally instantiate each player character. This works well, it detects which character is owned by which player and gives them access to movement if it's owned by the player. It also deletes unnecessary scripts and GameObjects on the player character prefab if it's the client isn't the owner (for example, the camera and a MouseLook script are being deleted now).

The problem is that I can't seem to get the NetworkViews to work properly. Each character has a NetworkView added to it when it's instantiated. I use Network.AllocateViewID() to set the NetworkViewID properly. I've tested with GUI and through the Inspector various times and this works (unless I'm mistaken): each player character has the same viewID on every client. It's set to observe the Transform with Reliable Delta Compressed as its state synchronization mode.

I've tested with two clients, but it doesn't work. The other player's movement is not sent across the network.

I thought it was because the players do not have a connection with each other, but rather only with the server, but when I tried to do the same method on the server, despite both NetworkViews having the same ID, the Transform wasn't being sent over.

So maybe I'm not fully aware of how NetworkViews work... I tried using NetworkView.SetScope() to true during the server test, but it didn't seem to make a difference.

What am I doing wrong?

Thanks in advance for any help that can be offered!

EDIT: Here's what the player character's script, Player.js, has inside it. I added some comments too. Mostly, it's a very simple movement system:

var translation:int; //Forward movement. -1, 0, or 1 based on input. var translation2:int; //Sideways movement. -1, 0, or 1 based on input. var functional:boolean = false; //Does this client own this Player? var transformNV:NetworkView; //'Transform Network View'. Another script //adds this NetworkView to the Player and sets it to Reliable Delta //Compressed and sets the Observed property to the Transform of the Player.

function Update() { if (functional) //If this script is owned by this client {

      if (Input.GetKey("w")) //Checking each Input key
         translation = 1; //Setting Translation based on it
      if (Input.GetKey("s"))
         translation = -1;
      if (Input.GetKey("a"))
         translation2 = -1;
      if (Input.GetKey("d"))
         translation2 = 1;
      
      if (!Input.GetKey("w") && !Input.GetKey("s"))
         translation = 0;
      if (!Input.GetKey("d") && !Input.GetKey("a"))
         translation2 = 0;
      if (translation != 0 || translation2 != 0) //Translating:
         transform.Translate((translation2 * 12) * Time.deltaTime,0,(translation * 12) * Time.deltaTime);
 }

}

Some more details about my testing, hopefully it'll help:

  • I tested the Client project with 1 instance running in the Unity editor and another running in a built client (it won't let me open the same project twice, so one has to be a built client instead of in the editor).

  • I have each client connected to a Server, which is running as a separate project in the Unity editor.

  • I'm sure that the connection is working. I've sent lots of RPCs between the server and the clients.

  • I use the server to AllocateViewID() and send that viewID via RPC to other clients.

  • I've used GUI.Label on the built client to display the viewID of each player in the game. I looked over the results using the Label and the Inspector of the other client, and the player NetworkViewIDs match.

Just now, I looked over it some more, and it seems the NetworkViewID of my 'main menu' NetworkView (on the client, used to connect to rooms and the server) is matching the other client's player's NetworkViewID (they're both 2). Is that the problem? The main menu's NetworkViewID is 'Scene' and the other is 'Allocated'. The NetworkView for the Main Menu is off because I used it only for RPCs to and from the server.

Comment
Add comment · Show 14
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 whydoidoit · Jun 01, 2012 at 08:42 AM 0
Share

Do you call AllocateViewID() after the server connection has been established?

avatar image whydoidoit · Jun 01, 2012 at 09:00 AM 1
Share

$$anonymous$$ind you on reflection I also ended up just sending position information by RPC because I needed a packet for animation state too. It used to work on the transform being observed though. Do you have lots of log entries about receiving information for a viewId that doesn't exist?

avatar image whydoidoit · Jun 01, 2012 at 11:14 PM 1
Share

When I allocateViewIDs for my players (on the player) then I always get them starting at 50+ BTW - no idea why, but that's what happens.

So my sequence is this:

  • Client connects to server

  • Client gets OnConnectedToServer message

  • Client creates networkView and allocates ViewID for avatar

  • Client send an AssignPlayer message to the server

  • Server broadcasts an AddPlayer message to all connected clients with the viewId for the new avatar

Obviously a bit of other data flies around in those calls like outfits, locations etc.

avatar image whydoidoit · Jun 02, 2012 at 09:02 AM 1
Share

Well it won't be much slower if you only send updates when things have changed (that's reliable covered), you could do you own deltas (I do that for my animation states, which I had to do because Unity couldn't auto sync my animation states properly and they are part of multi-player gameplay for me which isn't true for most games), I don't know what they are doing for compressed. I'm not sending much data and given networks have $$anonymous$$imum packet sizes I'm probably actually sending no more data than I would if I used the observed property.

avatar image whydoidoit · Jun 02, 2012 at 09:05 AM 1
Share

You'd have to interpolate anyway really - it's never really fast enough any other way.

You could also extrapolate too and blend the results if it becomes necessary.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

View ID AllocatedID: ### not found during lookup. Strange behaviour may occur 0 Answers

Photon PUN, HTC Vive camera prefab over network instantiation 0 Answers

Can I delay the instantiation of the network objects? 1 Answer

Get NetworkPlayer from ViewID 1 Answer

Couldn't Invoke RPC Function ! 1 Answer


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