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 Dec 19, 2012 at 07:03 PM by KiraSensei for the following reason:

Other

avatar image
0
Question by KiraSensei · Dec 03, 2012 at 09:28 PM · networkrpc

RPC call problem : local variable unvaluated ?

Hello everyone !

In my FPS game, I try to make a score dialog. To manage it, I have some informations in a script existing in all clients (and the server).

In the Awake() method of my player script I have these lines :

     if (!this.transform.parent.networkView.isMine)
     {
         enabled = false;
         return;
     }

To be sure that all the following code won't be called from another player.

So when one of the players has his life at 0, I call :

 networkView.RPC("NewKill", RPCMode.All, Network.player, by);

The called method is the following one :

 @RPC
 function NewKill (dead:NetworkPlayer, killer:NetworkPlayer) {
     var playersfound:int = 0;
     for (var currPlayer:PlayerData in playersList.players)
     {
        if (currPlayer.player == dead)
        {
          ++currPlayer.deaths;
          ++playersfound;
        }
        else if (currPlayer.player == killer)
        {
          ++currPlayer.kills;
          ++playersfound;
        }
        if (playersfound == 2) break;
     }
 }

When player1 kills player2, player2 has its data in the playersList var updated. I developped a dialog which displays on the screen the playersList data. I can see that player2 has the right data, but not player1, nothing was updated in its playersList var.

With the attached debugger I saw that player1 goes into the "NewKill" method but playersList does not contain anything, but it does when I call the method to display the scores ...

So I tested something else : still with the attached debugger, I added

 if (!this.transform.parent.networkView.isMine)
     {
         enabled = false;
         return;
     }

at the very beginning of the 'NewKill" method. And it goes into this "if" ... But my script is not disabled ! So I am in someone script but I don't know whose (player2 has its script enabled too), in which the playersList var containes nothing.

The comportement is symmetrical : if player2 kills player1, player1 has its data updated but player2 has no changes, so this should not be a client/server - server/client problem ...

Please help me :'( !

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

  • Sort: 
avatar image
0

Answer by TheDarkVoid · Dec 03, 2012 at 10:19 PM

It would probably be more efficient to have the script stay enabled, and instead prevent parts of the script from running if the networkView.isMine is false. Also it would also be best for the server to receive that RPC and determine who gets the kill and death, then you can send the updated list to all the other players. This is the way I have it in my game and it work well and it keeps score keeping on the server-side which is better for security.

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 KiraSensei · Dec 03, 2012 at 10:27 PM 0
Share

Why should the script stay enabled if it does not belong to the actual player ?

avatar image TheDarkVoid · Dec 03, 2012 at 10:30 PM 0
Share

if it's not enabled it cant receive data if it's not enabled, that is the main problem i can see with your code. Only the person who sends the RPC will receive it since all other receivers are disabled.

avatar image KiraSensei · Dec 03, 2012 at 10:50 PM 0
Share

I replaced the enable = false by a simple return, and I called this test on all interesting methods (awake, start, ongui), nothing changes on the behaviour, I still have no data in the playersList only for the New$$anonymous$$ill method :(

I don't really see any difference between sending only to the server the RPC and then it sends to all clients and doing what I am doing. I only increment ints and since RPC calls are queued, I'm not sure why I would not be safe. If you have any ideas I'm interested on them :)

avatar image TheDarkVoid · Dec 03, 2012 at 10:59 PM 0
Share

where is the RPC being called from?

avatar image KiraSensei · Dec 03, 2012 at 11:12 PM 0
Share

It is called from a script handled by one player.

I tested one thing : I initialize my playersList in the awake method. I tested the initialization before the test to know if the networkView is $$anonymous$$e, and oh magic it is working ! So I tested it with my first code (to disable the script if it is not $$anonymous$$e) and it is still working. I think it is working because the script of player1 is disabled only in player2 world, so the RPC call is still sent threw the network to player1, and since the script is enabled in player1 world there is no problem ... If someone lese knows exactly why, he may explain it here as a comment :)

So the thing I still don't understand is why the RPC call sent from player2 to player1 is applied to the script of player1 in player2 world (as the debugger sees it ...). It is now working but I don't really know why ...

Show more comments

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

RPC a lot of lags (Photon) 0 Answers

Unity3d Network - Cant See Connected Players 3 Answers

Really quick/easy question about RPCs 1 Answer

Getting rotation to work on client 1 Answer

Network RPC 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