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
1
Question by Drakeshe · Jan 11, 2012 at 03:14 AM · gameobjectrpcnetworkview

Unity crashes when doing an RPC.

Hey all, I'm trying to do a RPC but both the Unity Designer and Unity WebPlayer crash whenever it tries to do it. I therefore have no way of knowing what im doing wrong.

The GameObject that is running the below code is created by`Network.Instantiate` from a prefab with a NetworkView already attached.

Here is my update code:

 void FixedUpdate()
     //Unrelated code generating vehicles wheel movement.
     if(networkView.isMine)
     {
         SetInputHorizontal(Input.GetAxisRaw("Horizontal"));
         SetInputHorizontal(Input.GetAxisRaw("Vertical"));
     }
     //Unrelated code setting wheel movement.
 }

Here are the RPC functions:

     [RPC]
     public void SetInputVertical(float InputVal)
     {
         if(networkView.isMine && vertInput != InputVal)
         {
             networkView.RPC("SetInputVertical", RPCMode.All, InputVal);
         }
         vertInput = InputVal;
     }
     
     [RPC]
     public void SetInputHorizontal(float InputVal)
     {
         if(networkView.isMine && horizInput != InputVal)
         {
             networkView.RPC("SetInputHorizontal", RPCMode.All, InputVal);
         }
         horizInput = InputVal;
     }

The game will run, but whenever I press an input key triggering the change in input, thus triggering the RPC, Unity totally crashes.

Anyone got an idea as to what I'm doing wrong?

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 syclamoth · Jan 11, 2012 at 03:29 AM

Take a look at this function-

 [RPC]
 public void SetInputVertical(float InputVal)
 {
    if(networkView.isMine && vertInput != InputVal)
    {
      networkView.RPC("SetInputVertical", RPCMode.All, InputVal);
    }
    vertInput = InputVal;
 }

What does it do?

First, it checks to see if the networkView is local. If it is, it sends an RPC to everyone, and finishes.

However, 'everyone' includes the local machine! So every time this RPC gets called, it recursively calls itself again! So, every time you call this function (RPC or not), it will create an infinite loop.

You should use RPCMode.Others, instead.

Comment
Add comment · Show 3 · 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 syclamoth · Jan 11, 2012 at 03:30 AM 0
Share

(I once had a similar problem, except that it only manifested if there were at least three clients connected! That one took a while to fix, let me tell you.)

avatar image Drakeshe · Jan 11, 2012 at 03:32 AM 0
Share

Oh ok, I was told that RPC$$anonymous$$ode.All doesn't call itself. I guess I'll change it to RPC$$anonymous$$ode.Others then and see if it fixes it.

avatar image Drakeshe · Jan 11, 2012 at 03:38 AM 0
Share

PERFECT! It works great. $$anonymous$$y character drives around just like he were a local player.

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

Force a RPC to be called on a networkview of another GameObject 1 Answer

Problem with Network Connection 1 Answer

A node in a childnode? 1 Answer

Making changes to a terrian in game 1 Answer

How to create 3D game object in specified pixel size? 2 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