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 KiraSensei · Dec 25, 2012 at 01:42 PM · networkrpc

Server/Client problem : rpc call

Hello everyone !

First of all, merry christmas :)

I have a problem in my FPS game when I try to handle damages with a specific weapon.

This script is attached to a player's knife :

 var isShootenBy:NetworkPlayer;
 private var firstShootDone:boolean = false;
 
 function OnTriggerEnter (other:Collider)
 {
     if (firstShootDone) return;
     if (other.networkView && other.networkView.owner == isShootenBy) return;
     
     if (other.gameObject.tag == "joueur")
     {
         firstShootDone = true;
         Debug.Log("joueur touché au couteau");
         Hit(other.transform);
     }
     yield WaitForSeconds(0.24f);
     firstShootDone = false;
 }
 
 function Hit(obj:Transform) {
     var currParent:Transform = null;
     if (!obj.parent) currParent = obj;
     else
     {
         var nextParent:Transform = currParent;
         while (nextParent)
         {
             currParent = nextParent;
             nextParent = nextParent.parent;
         }
     }
     
     currParent.GetComponentInChildren(PlayerScript).networkView.RPC("IsHitBy", currParent.networkView.owner, 0, isShootenBy);
 }

It sends to the shot player some intel like what weapon hit him, and who shot him.

Then, on my player game object I have a PlayerScript attached to its son that contains the "isHitBy" method :

 @RPC
 function IsHitBy (from:int, by:NetworkPlayer) {
     if (isDead) return;
     var damages = 0;
     switch (from) {
         case Weapon.Couteau:
             damages = couteauDamage;
             break;
         case Weapon.Arbalete:
             damages = arbaleteDamage;
             break;
         case Weapon.LanceFlammes:
             damages = lanceFlammesDamage;
             break;
         case Weapon.Minigun:
             damages = minigunDamage;
             break;
     }
 }

My problem is the following : when the client player hits the server player, the server player looses life (correct behavior), when the server player hits the client player, I have a core dump, big crash and the windo closes...

So here is what I already tried to find the problem : if I comment the rpc call on IsHitBy from my knife script, everything is fine (but damages are not applied anymore ... logic), if I let this line uncomment, but I comment everything IN IsHitBy, then I still have a core dump. Both my players are instantiated in the same way, there are both instances of the same prefab.

Thanks by advance to anyone who can 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

· Add your reply
  • Sort: 
avatar image
0

Answer by asafsitner · Dec 25, 2012 at 03:40 PM

One problem I can identify immediately is that the player cannot send RPC to another player directly by themselves, unless that other player is the server.

Because the server is connected to everyone, the server knows the other players by 'name' (i.e. by their NetworkPlayer struct) so the server can refer to each player individually.

The clients, on the other hand, are only directly connected to the server, so they can only ever send an RPC to the server. If they send an RPC with a RPCMode different than 'RPCMode.Server` what happens is that the player sends the RPC to the server, which then relays the RPC to the relevant players, according to the flag (All or Others).

This is again, because the player can't send an RPC to others by themselves.

Comment
Add comment · Show 4 · 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 25, 2012 at 03:47 PM 0
Share

So if I understand correctly, my code should only work when the server player hits a client player ? Because it is the opposite that happens ...

EDIT : the thing is I use the same code with an other weapon and everything is fine ...

avatar image asafsitner · Dec 25, 2012 at 04:14 PM 0
Share

I guess I got confused by 'when the server player hits the client player, I have a core dump, big crash and the windo closes...'

avatar image KiraSensei · Dec 25, 2012 at 04:19 PM 0
Share

I tested something else :

if (Network.isServer) currParent.GetComponentInChildren(PlayerScript).networkView.RPC("IsHitBy", currParent.networkView.owner, 0, isShootenBy);

else currParent.GetComponentInChildren(PlayerScript).networkView.RPC("BiduleIsHitBy", RPC$$anonymous$$ode.Server, currParent.networkView.owner, 0, isShootenBy);

So with that I test if the shooter player is the server, if yes I directly send (as before) the intel to the shot player, if not, I send the intel to the server who redirect them to the concerned player. This is not working at all :)

I always go to the "else" part...

avatar image KiraSensei · Dec 25, 2012 at 04:26 PM 0
Share

Damn ! I don't understand why, but if I put the test :

@RPC

function BiduleIsHitBy (target:NetworkPlayer, from:int, by:NetworkPlayer) {

 if (Network.isServer) IsHitBy(from, by);
 else networkView.RPC("IsHitBy", target, from, by);

}

in this method, everything works !!

So my problem looks solved, it looked like it was something really close to what you said, but I can't explain why in my weapon script I go everytime in the "else" part, like no one was the server ...

Edit : if my function is :

@RPC

function BiduleIsHitBy (target:NetworkPlayer, from:int, by:NetworkPlayer) {

 IsHitBy(from, by);

}

It works very well too, I really don't understand what's happening ...

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

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

Does the position change need state synchronization? 2 Answers

RPC and inheritance 1 Answer

Send GameObject active in network to all clients 2 Answers

Disconnect a player from a network 1 Answer

Network.Destroy(), Couldn't perform remo 0 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