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
1
Question by PatrikNyblad_SI · Oct 03, 2011 at 09:32 AM · networkrpcstartnetworkviewnetwork view

Can not make RPC calls during Start()

Hi!

Last week I started working on a network project in Unity. I have been using unity for quite a while and are familiar and comfortable with the documentation.

The Problem:

Making RPC-calls is a pice of cake (Thanks Unity) but there seems to be some problems... Making a RPC-call while playing the game is fine (doing this in the Update() loop) but when trying to do it in the Start() function fails.

I looked at the Execution order documentation to see if I needed to set the Network view before the monobehaviour making the RPC-call but no improvement. I also check to see if the Network view component is there before running my RPC-call and it says that it is there but i still get no response.

Here is the example that i have been using:

 private var runOnce : boolean = false;
 private var startTime : float;

 function Start(){

   startTime = Time.time;
   if (networkView){
     
     Debug.Log("NetworkViewExists!");
     networkView.RPC ("PrintText", RPCMode.All, "Hello worldASDASDASDASDASDASDASDA!");
 
   }

 }

 function Update(){
   if (!runOnce && Time.time - startTime > 0.4){
     networkView.RPC ("PrintText", RPCMode.All, "Hello worldASDASDASDASDASDASDASDA!");
     runOnce = true;
   }

 }

 @RPC
 function PrintText (text : String, info : NetworkMessageInfo)
 {
     Debug.Log(text + " from " + info.sender);
 }

If i set the wait to a time like 0.4 seconds that call comes through but anything lower then that is just lost and the start call is never run at all. I will get a result if I make a yield WaitForSeconds(1) and then running the RPC-call from Start. Another thing i have tried is to make the call AllBuffered but no difference.

Output:

NetworkViewExists! UnityEngine.Debug:Log(Object) RPCTest:Start() (at /Users/patriknyblad/Dropbox/carmine/Games/NetworkTest/Assets/RPCTest.js:9)

Hello worldASDASDASDASDASDASDASDA! from -1 UnityEngine.Debug:Log(Object) RPCTest:PrintText(String, NetworkMessageInfo) (at /Users/patriknyblad/Dropbox/carmine/Games/NetworkTest/Assets/RPCTest.js:27) UnityEngine.NetworkView:RPC(String, RPCMode, Object[]) RPCTest:Update() (at /Users/patriknyblad/Dropbox/carmine/Games/NetworkTest/Assets/RPCTest.js:18)

Wrapup:

Why cant I make an RPC-call in the Start() function and why cant I make an RPC-call until 0.4 seconds from the start of the component?

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
3
Best Answer

Answer by PatrikNyblad_SI · Oct 03, 2011 at 12:17 PM

OK!

So my project was based on a few scripts from the Unity Network Tutorial and i have not read them thoughroly enough. A NetworkView belongs to a Network.group, unity sets up a default group with ID 0 for you. You can offcourse split your communication into different groups and handle traffic the way you want to.

Now that we access the Network.group we can set it to receive or not receive network messages which in turn one of the Unity Scripts was doing.

The Unity Network Level Load disables communication over Network.group 0 when loading a new level and waits for the level to load before enabling the network messages again. It is doing this for good reason tho because you might recieve calls from objects in the old level while you have loaded the new one because your other clients are slow and have not yet got the update or due to queued messages through RPC or sync.

My simple solution is to create a new network group at load of the script and then i set the sending to enabled for this group and add my networkview to that network group.

I see what I did wrong and now it works in my sample project. I just have to implement it into my real project.

I hope this is good reading for someone else out there!

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

2 People are following this question.

avatar image avatar image

Related Questions

Does the position change need state synchronization? 2 Answers

Help with Network Script. Game with multiple Maps. 2 Answers

RPC Player Name and show it above head 0 Answers

AllocateViewID over RPC but the NetworkView doesn't exist 2 Answers

View ID AllocatedID: # not found during lookup. Strange behaviour may occur 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