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 Omar47i · May 20, 2014 at 10:26 PM · networkingrpcnetworkviewviewid

Couldn't Invoke RPC Function !

Hi every one I assume that my question is very simple but actually i spent hours or even days to solve my problem withuot any result, now i have a simple non-authoritative server game in which whenever a player connects to the server i.e. when OnConnectedToServer(), a player character is network instantiated with a set of preallocated networkViews

 void OnConnectedToServer()
     {
         // spawn the player on connected to server
         Network.Instantiate(playerPrefab, new Vector3(startPosX, startPosY, startPosZ), Quaternion.identity, 0);
     }

each player prefab has multiple network views for different tasks (two for transform and animation sync and another two for rpc calls), i implemented a private chat app that each client can chat directly to another client connected to the server. seems no problem until now but the annoying message that keeps popup is when i send an rpc call to another client

View ID AllocatedID: 0 Level prefix: 0 not found during lookup. Strange behaviour may occur

and

Couldn't invoke RPC function 'FunctionName' because the networkView 'SceneID: 0 Level Prefix: 0' doesn't exist

to clear things out each player has his own 4 networkViews i mentioned earlier so in my opinion i can't just send rpc function from my networkView to another player's networkView even if they share the same script am i right ? (each player prefab has these networkViews), so i tried to forward the rpc function to the server and then the server forward it to the target client and actually it worked some times but now not. i tried to call the rpc function on the target player insted from whithin my player like this:

 targetTransform.networkView.RPC("RPCFunctionName", targetNetworkPlayer, arg1, arg2);

 

but with no result, i tried also to activate the gameObject that the networkView is attached to before starting the game becuz the player starts with the cild that this networkView is attached to deactivated, the same error

any help will be appreciated and if i misunderstood the functionality of allocating view ids any coorection will be 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
0
Best Answer

Answer by Jix · May 20, 2014 at 10:37 PM

Ok, maybe having multiple networkViews on your playerPrefab is causing problems, I usually use just one for everything i want (transform, RPCs)

Also (just in case you're not doing it) did you write [RPC] before your function like this?

 [RPC]
 void RPCFunctionName()
 {
 }
Comment
Add comment · Show 6 · 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 Omar47i · May 21, 2014 at 09:32 AM 0
Share

unfortunately i can't use only one networkView, i can use at least two networkViews to observe transform and animation components and also this wont work becuz the scripts that is attached to children of playerPrefab that uses RPC functions will net be able to access these two networkViews (i cant put all rpc dependant scripts on the plaeyrPrefab parent game object) .

avatar image Omar47i · May 21, 2014 at 09:35 AM 0
Share

but if u have a better idea in dealing with sending data on remote devices than just attach a networkView whenever the script in the child playerPrefab want to send data remotly ?

avatar image Jix · May 22, 2014 at 12:06 AM 0
Share

Well, if I need to sync transformation and send RPC at the same time I set the networkView to RPC mode and send all the info I want in one RPC function, I can't send transform directly due to RPC argument type limitation but I send the position and rotation and make the receiver object translate to this position and rotate.

If the receiver will collide with object then I send velocity too because if an object(A) is just translating and touch another object(B) while (A) has velocity = 0 then it will just move (B) a little ins$$anonymous$$d of pushing it. Objects need velocity to actually push another object.

RPC calls have limited arguments (int, float, string, NetworkPlayer, NetworkViewID, Vector3, Quaternion) so if you want to send objects you have to be creative, for example if an object has 2 int and 1 float you can send your object in pieces or even better in a single Vector3 then deal with its component in the receiving function.

As for animations I haven't tried it before in RPC but I think you can send the name of the animation and the current time of the animation.

I know it's a lot of work to do but believe me it's not slower than the regular networkView that sync transform since you can send what you need exactly, for example if you don't care about rotation but just want the position. And it can save performance since you can call these RPC calls only when needed. It's a possible scenario that you want to sync the position of an object at a certain time.

Also bear in $$anonymous$$d that when there is an object not controlled directly by players (like the ball in a football game) let the server is the one to update its info to all players.

I too tried before to put several networkViews like you and it failed terribly, the solution I offer is hard and may cause conflicts if not planned carefully but it works and has good performance, I tested it on low speed internet connection (download/upload rates 100/20 kbps)

avatar image Jix · May 22, 2014 at 12:15 AM 0
Share

I forgot to add important note:Unity's physics engine doesn't give the same results for the same inputs, for example when a player kicks a ball in direction x with force y on one PC and you send x and y the other PC's physics engine might give different result, so you can ins$$anonymous$$d send the result.

avatar image Omar47i · May 22, 2014 at 11:23 AM 0
Share

from ur well-written explanation what i understand is the following points:

  • A lot of networkViews is bad thing for a single prefab.

  • state sync decreases performance and increases network bandwidth.

  • ins$$anonymous$$d of state sync it's preferable to serialize data when needed

  • Network.Instantiate is a nightmare so use RPC with viewID as parameter if i want to instantiate a player on all other machines

  • u didn't mention any thing about OnSerializeNetworkView so ithink its not recommended for sync position, rotation and animation right ?

this all very good and i actually started to apply that but here is the problem if u could clarify more i will be very thankful

first is it preferable to AddComponent() to each player prefab on instantiation or just attach the networkView before runtime and then assign a ViewID to him and reflect that to all players, second the player parent and all the position, rotation, and animation will be sync using rpcs but what if a child gameObject want to send rpc to another player that has also this child gameObject do i refer to that player locally and then call the rpc on his player prefab or i can't send an rpc directly to a specific client (this is by the way the error message that i described in the question when sending data to a specific client) ?

Show more comments

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

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

Get NetworkPlayer from ViewID 1 Answer

networkView not called on Child objects? 0 Answers

Networking Error! 0 Answers

OnSerializeNetworkView issus in my 2D game 3 Answers

Overloading RPCs 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