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 /
This question was closed Jan 01, 2013 at 11:25 PM by KiraSensei for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by KiraSensei · Dec 23, 2012 at 07:43 PM · coroutinerpcyield

Var change between 2 RPC calls / Coroutine problem

Hello everyone !

I encountered a network problem :
I have 2 RPC calls following each other, with a yield between them. One of their attributes is a public boolean variable contained in the same script. In some cases, this boolean changes while the yield is happening. My problem is that the second RPC call does not take in account this change ...

Here is the code to be more clear :

 var minigunFireAborted:boolean = false;

 function Update() {
     if (Input.GetButton("Fire1") && (currentWeapon == Weapon.Minigun || currentWeapon==Weapon.LanceFlammes) )
     {
         RafaleFire();
     }
     if (Input.GetButtonUp("Fire1"))
     {
         minigunFireAborted = true;
         networkView.RPC("NetworkAnimateMinigun", RPCMode.All, 3, minigunFireAborted);
         networkView.RPC("NetworkAnimateMinigun", RPCMode.All, 4, minigunFireAborted);
     }
 }

 function RafaleFire()
 {
     networkView.RPC("NetworkAnimateMinigun", RPCMode.All, 1, minigunFireAborted);
     yield WaitForSeconds(1.0f);
     networkView.RPC("NetworkAnimateMinigun", RPCMode.All, 2, minigunFireAborted);
 }

 @RPC
 function NetworkAnimateMinigun (anim:int, aborted:boolean) {
     var audios:Component[]= instanceMinigun.GetComponentsInChildren(AudioSource);
     switch (anim) {
         case animationMinigun.MinigunIdle:
             instanceMinigun.animation.PlayQueued("idle");
             break;
         case animationMinigun.MinigunStart:
             instanceMinigun.animation.Play("start");
             MakeNoiseFromMinigun("rotation_minigun_start", audios, true);
             break;
         case animationMinigun.MinigunShoot:
             instanceMinigun.animation.PlayQueued("shoot");
             if (!aborted)
             { // HERE IS THE PROBLEM, ABORTED IS ALWAYS FALSE EVEN IF THE PLAYER RELEASED FIRE1
                 MakeNoiseFromMinigun("rotation_minigun_shoot", audios, true);
                 MakeNoiseFromMinigun("shoot_minigun", audios, true);
             }
             break;
         case animationMinigun.MinigunStop:
             instanceMinigun.animation.Play("stop");
             MakeNoiseFromMinigun("rotation_minigun_shoot", audios, false);
             MakeNoiseFromMinigun("rotation_minigun_stop", audios, true);
             break;
         case animationMinigun.MinigunWithoutAmmo:
             MakeNoiseFromMinigun("shoot_minigun", audios, false);
             break;
     }
 }

Thanks by advance for the help !

EDIT : this appears to be a problem with the coroutine RafaleFire(). If someone has an idea ... It seems that since RafaleFire() is a coroutine, then changes that appear in the 1 secon lap time in the Update() method are not taken in account. The coroutine continues with the "previous" state of variables when it was firstly launched ...

Comment
Add comment · Show 2
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 KiraSensei · Dec 24, 2012 at 12:19 AM 0
Share

Damn ! I was sure of the opposite, a boolean var is so basic... Thanks, it works perfectly, if you want to change the comment as an answer to be validated ...

avatar image asafsitner · Dec 24, 2012 at 12:33 AM 0
Share

I know... I usually sent an int as 0/1 for false/true ins$$anonymous$$d. It's a bit annoying, but nothing we can do about it :)

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by asafsitner · Dec 23, 2012 at 11:24 PM

Seems to me the problem is with your RPC declaration; RPCs cannot have a boolean parameter!
See here for more details.

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

Follow this Question

Answers Answers and Comments

10 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

Related Questions

www class blocks script execution 1 Answer

Figuring out Coroutines 3 Answers

How to start at a specific coroutine? 0 Answers

Trouble Resuming after Yielding while Inside Coroutine 1 Answer

WaitForSeconds Question 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